prompt method
Displays a Prompt dialog box with a message and an input field.
语法
prompt(message, [inputDefault])
message is any string or a property of an existing object; the string is displayed as the message.
inputDefault is a string, integer, or property of an existing object that represents the default value of the input field.
<html>
<head>
<title>
</title>
<script language="javascript">
<!--
function show()
{
var name
name=window.prompt("please enter your name:","")
window.alert(name)
}
//-->
</script>
</head>
<body>
<input type="button" name="button1" value="click" onclick="show()">
</body>
</html>
这个例子是点击按钮才出现对话框,且名字是由一新的窗口显示。如果想显示到页面上,只用把
window.alert(name)换成:
document.write(name)
document.close()
如果想页面完全载入后直接弹出窗口,则如下:
<html>
<head>
<title>
</title>
<script language="javascript">
<!--
function show()
{
var name
name=window.prompt("please enter your name:","")
document.write(name)
document.close()
}
//-->
</script>
</head>
<body onload="show()">
</body>
</html>