您的位置:首页 > Web前端 > JavaScript

JavaScript学习与实践(10)

2007-01-21 23:11 453 查看
在脚本JS中,你可以创建三种弹出对话框,限于我的编辑器,请大家自己,复制脚本去练习,Alertbox,Confirmbox,andPromptbox.



<html>
<head>
<scripttype="text/javascript">
functiondisp_alert()
{
alert("Iamanalertbox!!")
}
</script>
</head>
<body>
<inputtype="button"onclick="disp_alert()"value="Displayalertbox"/>
</body>
</html>



<html>
<head>
<scripttype="text/javascript">
functiondisp_alert()
{
alert("Helloagain!Thisishowwe"+'\n'+"addlinebreakstoanalertbox!")
}
</script>
</head>
<body>
<inputtype="button"onclick="disp_alert()"value="Displayalertbox"/>
</body>
</html>


<html>
<head>
<scripttype="text/javascript">
functiondisp_confirm()
{
varr=confirm("Pressabutton")
if(r==true)
{
document.write("YoupressedOK!")
}
else
{
document.write("YoupressedCancel!")
}
}
</script>
</head>
<body>
<inputtype="button"onclick="disp_confirm()"value="Displayaconfirmbox"/>
</body>
</html>



<html>
<head>
<scripttype="text/javascript">
functiondisp_prompt()
{
varname=prompt("Pleaseenteryourname","HarryPotter")
if(name!=null&&name!="")
{
document.write("Hello"+name+"!Howareyoutoday?")
}
}
</script>
</head>
<body>
<inputtype="button"onclick="disp_prompt()"value="Displayapromptbox"/>
</body>
</html>
弹出对话框alert,当需要用户明确一种事件要执行,用户确定之后才能继续进行下去,
语法:
alert("sometext")

弹出对话框ConfirmBox,他用于用户确认或者校验的时候用的多,,用户可以选择,确定或者取消,如果确定就继续,要是选择,取消,程序就不会执行下去了。语法是:


confirm("sometext")

弹出对话框PromptBox,他是用于使用户输入一个数值,并返回这个输入数值,并执行下面的程序,

语法:


prompt("sometext","defaultvalue")


                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: