现在的位置: 首页 > 综合 > 正文

confirm() 方法

2013年08月05日 ⁄ 综合 ⁄ 共 667字 ⁄ 字号 评论关闭

 

Code:
  1. <html>  
  2.     <head>  
  3.         <title>HelloWord</title>  
  4.         <script type="text/javascript">  
  5.             window.onload = writeMessage;  
  6.             s = "";  
  7.             function writeMessage(){  
  8.                 document.getElementById("helloMessage").innerHTML   = s;  
  9.             }  
  10.             if(confirm("Are you sure you want to do that?")){  
  11.                 s = "You said yes";  
  12.                 alert(s);  
  13.             }else{  
  14.                 s = "You said no";  
  15.                 alert(s);  
  16.             }  
  17.         </script>  
  18.     </head>  
  19.     <body>  
  20.         <h1 id="helloMessage"></h1>  
  21.     </body>  
  22. </html>  

confirm()方法有一个参数(向用户询问的问题),并根据用户的响应返回true或false

抱歉!评论已关闭.