该函数实际上称为prompt()
var bananas = prompt("Please type how many bananas you'd like");
alert("Here you have "+ bananas +" number of bananas. Smile!");
如果要使输入字段锁定页面,则必须在页面上进行某种叠加,并在其上显示输入;禁止用户进行除字段外的任何其他交互。
编辑:通过叠加我的意思是这样的:
HTML
<html>
<body>
<div id="overlay"></div>
<form id="field">
<input type="text" name="test" />
<input type="submit" value="Continue" />
</form>
</body>
</html>
CSS
#overlay {position:absolute; top:0; left:0; width:100%; height:100%; background:rgba(0,0,0,0.5);}
#field {position:absolute; width:200px; height:200px; top:50%; left:50%; margin:-100px 0 0 -100px; z-index:10;}
JavaScript
$('#field').on('submit', function(e) {
e.preventDefault();
// Do some validation and such, and when done, hide the overlay and field
$('#field, #overlay').hide();
});