- <html>
- <head>
- <title>HelloWord</title>
- <script type="text/javascript">
- window.onload = writeMessage;
- s = "";
- function writeMessage(){
- var ans = prompt("Are you sure you want to do that?","");
- if(ans){
- alert("You said " + ans);
- }else{
- alert("You refused to answer");
- }
- }
- </script>
- </head>
- <body>
- </body>
- </html>
prompt()方法参数:向用户询问的问题和默认回答。这个方法返回用户的响应或null。
var的作用:
1、创建一个变量(在内存中为这个对象留出一些空间)
2、定义变量的scope