javascript弹出框
1.警告框
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> </head> <body> <script> window.alert("hello,world"); </script> </body> </html>2.确认框
代码为
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> </head> <body> <button onclick="action()">请随便输入</button> <span id="show"> 这里显示你的输入</span> <script> function action(){ var x = window.confirm("确认付款?") if(x ==true){ document.getElementById("show").innerHTML = "确认"; }else{ document.getElementById("show").innerHTML = "不买"; } } </script> </body> </html>
3.提示输入框
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> </head> <body> <button onclick="action()">请随便输入</button> <span id="show"> 这里显示你的输入</span> <script> function action(){ var x = window.prompt("请输入你的名字"); document.getElementById("show").innerHTML = x; } </script> </body> </html>
总结:
1.其实上面的window.都可以去掉
2.js里面很多有window和document开头,这是套路