JavaScript中confirm,alert,prompt的用法

来源:互联网 发布:阿里云 安全组规则 编辑:程序博客网 时间:2024/05/05 12:21

window.confirm 参数就只有一个。显示提示框的信息。按确定,返回true;按取消返回false。   

  1. < SCRIPT>     
  2. var bln = window.confirm("确定吗?");     
  3. alert(bln)     
  4. < /SCRIPT> 

window.alert参数,只有一个,显示警告框的信息;无返回值。   

  1. < SCRIPT>     
  2. window.alert("确定。")   

window.prompt参数,有两个,第一个参数,显示提示输入框的信息。第二个参数,用于显示输入框的默认值。返回,用户输入的值。 

  1. < SCRIPT>     
  2. var str = window.prompt("请输入密码","password")     
  3. alert(str);     
  4. < /SCRIPT>  

</pre><pre code_snippet_id="677881" snippet_file_name="blog_20150528_3_5271709" name="code" class="html"><html><head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script type="text/javascript">function show_alert(){alert('第一行\n第二行');}function show_confirm(){var result = confirm('是否删除!');if(result){alert('删除成功!');}else{alert('不删除!');}}function show_prompt(){var value = prompt('输入你的名字:', '默认名字');if(value == null){alert('你取消了输入!');}else if(value == ''){alert('姓名输入为空,请重新输入!');show_prompt();}else{alert('你好,'+value);}}</script></head><body><input id="alert_button" type="button" value="alert" onclick="show_alert()" ><input id="confirm_button" type="button" value="confirm" onclick="show_confirm()" ><input id="prompt_button" type="button" value="prompt" onclick="show_prompt()" ></body></html>

0 0