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,当需要用户明确一种事件要执行,用户确定之后才能继续进行下去,
语法:
一
<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")
相关文章推荐
- 【学习笔记javascript设计模式与开发实践(组合模式)----10】
- 【学习笔记javascript设计模式与开发实践(组合模式)----10】
- Java程序员的JavaScript学习笔记(10—— jQuery-在“类”层面扩展)
- Web前端开发最佳实践(10):JavaScript代码不好读,不好维护?你需要改变写代码的习惯
- (10)JavaScript学习笔记 - 数组
- 【学习笔记javascript设计模式与开发实践(代理模式)----6】
- C#.Net Castle ActiveRecord学习实践(10):深度分析Schema Pitfals
- JavaScript学习与实践(25)
- JavaScript学习与实践(26)(高级操作)
- 10 个你需要了解的最佳 javascript 开发实践
- JavaScript学习总结(10)——实用JS代码大全
- bootstrap 学习之路 10 (javascript DOM 编程)
- JavaScript学习与实践(4)
- JavaScript学习与实践(9)
- JavaScript学习与实践(15)
- 【学习笔记javascript设计模式与开发实践(命令模式)----9】
- 【学习笔记javascript设计模式与开发实践(单例模式)----4】
- 【学习笔记javascript设计模式与开发实践(策略模式)----5】
- JavaScript学习10:动态载入脚本和样式
- 【学习笔记javascript设计模式与开发实践(迭代器模式)----7】