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")
浙公网安备 33010602011771号