JavaScript 中用什么函数可以弹出一个窗口出来,并且可以输入字符串?
怎样接收这个字符串? 希望能有一个例子,谢谢!!!
var mm = prompt("提示", "缺省值");
alert(mm);
<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>
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.
prompt("title","value")
alert("msg")
confirm("msg")
function inp()
{
var msg;
msg=prompt("请输入字符串:","输入这里");
alert("输入信息是:"+msg);
}
可以,用window.open或showmodeldialg做