- <html>
- <head>
- <title>HelloWord</title>
- <script type="text/javascript">
- window.onload = writeMessage;
- s = "";
- function writeMessage(){
- document.getElementById("helloMessage").innerHTML = s;
- }
- if(confirm("Are you sure you want to do that?")){
- s = "You said yes";
- alert(s);
- }else{
- s = "You said no";
- alert(s);
- }
- </script>
- </head>
- <body>
- <h1 id="helloMessage"></h1>
- </body>
- </html>
confirm()方法有一个参数(向用户询问的问题),并根据用户的响应返回true或false