码迷,mamicode.com
首页 > Web开发 > 详细

js本身实现的弹出框

时间:2014-06-11 07:08:39      阅读:257      评论:0      收藏:0      [点我收藏+]

标签:javascript   弹出框   web前端   

一: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>
bubuko.com,布布扣

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>

bubuko.com,布布扣

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

bubuko.com,布布扣

如果点击取消,则弹出显示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>

bubuko.com,布布扣

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

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

bubuko.com,布布扣



js本身实现的弹出框,布布扣,bubuko.com

js本身实现的弹出框

标签:javascript   弹出框   web前端   

原文地址:http://blog.csdn.net/woaipaiqiu/article/details/29261385

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!