js本身实现的弹出框

来源:互联网 发布:网络直播评论 编辑:程序博客网 时间:2024/05/16 14:07

一:js现有的弹出框

1.alert(message)

message为要在弹出框内显示的纯文本;

<html><script>function show_alert(){   alert('hello');            }</script><body><tr><td><input type=button id=btn1 name=btn1 value=alert onclick=show_alert();></td></tr></body></html>

2.确定提示框confirm

confirm(message)

message为要在提示框上显示的纯文本(不是HTML文本)

<html><script>function show_confirm(){    if(confirm('Are you sure ?'))        alert('yes');   else        alert('no');}</script><body><tr><td><input type=button id=btn2 name=btn2 value=confim onclick=show_confirm();></td></tr></body></html>


点击确定或回弹出以下对话框


如果点击取消,则弹出显示no的对话框

3.输入提示框prompt

prompt(text,defaultText)

text为在输入框上面显示的纯文本,defauleText为输入框中默认显示的内容;这两个参数都是可选的。


<html><script>function show_input(){    var city=prompt('请输入您的省市','山东');   if(city!=null && city!='')    {         var str= city + '是个好地方';         alert(str);    }}</script><body><tr><td><input type=button id=btn3 name=btn3 value=prompt onclick=show_input();></td></tr></body></html>


山东是默认的defaultTex,如果不选择这个参数的话,文本框中为空;

点击确定后,会弹出另一个对话框:



0 0
原创粉丝点击