• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
龙星之峰
抓住时间,改变现状
博客园    首页    新随笔    联系   管理    订阅  订阅

JavaScript学习与实践(10)

在脚本JS中,你可以创建三种弹出对话框,限于我的编辑器,请大家自己,复制脚本去练习,Alert box, Confirm box, and Prompt box.

一

<html>
<head>
<script type="text/javascript">
function disp_alert()
{
alert("I am an alert box!!")
}
</script>
</head>
<body>

<input type="button" onclick="disp_alert()" value="Display alert box" />

</body>
</html>

 

二

 

<html>
<head>
<script type="text/javascript">
function disp_alert()
{
alert("Hello again! This is how we" + '\n' + "add line breaks to an alert box!")
}
</script>
</head>
<body>

<input type="button" onclick="disp_alert()" value="Display alert box" />

</body>
</html>

三

 

<html>
<head>
<script type="text/javascript">
function disp_confirm()
{
var r=confirm("Press a button")
if (r==true)
{
document.write("You pressed OK!")
}
else
{
document.write("You pressed Cancel!")
}
}
</script>
</head>
<body>

<input type="button" onclick="disp_confirm()" value="Display a confirm box" />

</body>
</html>

 

四

 

<html>
<head>
<script type="text/javascript">
function disp_prompt()
{
var name=prompt("Please enter your name","Harry Potter")
if (name!=null && name!="")
{
document.write("Hello " + name + "! How are you today?")
}
}
</script>
</head>
<body>

<input type="button" onclick="disp_prompt()" value="Display a prompt box" />

</body>
</html>

弹出对话框alert,当需要用户明确一种事件要执行,用户确定之后才能继续进行下去,

语法:

alert("sometext")
弹出对话框Confirm Box,他用于用户确认或者校验的时候用的多,,用户可以选择,确定或者取消,如果确定就继续,要是选择,取消,程序就不会执行下去了。语法是:
 
confirm("sometext")
弹出对话框Prompt Box,他是用于使用户输入一个数值,并返回这个输入数值,并执行下面的程序,
语法:
 
prompt("sometext","defaultvalue")
 
posted @ 2007-01-21 23:11  lxsohu  阅读(243)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3