[英]I need to show error when user presses escape on prompt box , but code below doesnt seem to work, any answers?
function(catchError) {
try {
var firstname = prompt("please enter your first name");
}
catch (error) {
alert(error.message);
}}
1. how can I remove this problem 1.如何解决此问题
2 also make this work in google chrome 2也可以在谷歌浏览器中使用
prompt
will return null
if cancel or the escape key is pressed. 如果取消或按退出键,
prompt
将返回null
。 Just check for it: 只需检查一下:
var firstname = prompt("please enter your first name");
if(firstname !== null) {
} else {
// ESC or cancel pressed
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.