简体   繁体   English

当用户在提示框上按Escape键时,我需要显示错误,但是下面的代码似乎不起作用,任何答案?

[英]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.

相关问题 当用户按下按钮时,如何在 react-native 中实现以下代码 - How do you achieve the below code in react-native when user presses a button 当用户关闭任何特定选项卡时如何显示提示? (这是关于单个选项卡,而不是所有浏览器的) - How do i show prompt when user close any particular tab? (This is about individual tab not for all browser) 当用户单击任何圆圈时,我想显示以下效果。 考虑粉红色圆圈 - When User clicks on any circle I want to show the below effect. Consider Pink color circle 这个js代码不起作用,我需要另一双眼睛 - this js code doesnt work and i need another pair of eyes here 当用户按下回车键时,输入框是否可以运行功能? - Is there a way for a input box to run a function when the user presses the enter key? 这个反应代码中的错误是什么? 当我在第 1 部分中调用 function 时它不起作用但第 2 部分有效 - What is the error in this code of react? When i call the function in part 1 it doesnt work but part 2 works .className()似乎不起作用 - .className() seem doesnt Work setDeleteFileParams似乎不起作用 - setDeleteFileParams doesnt seem to work 我转到了 javascript 学习班,下面的代码似乎不起作用 - I moved to learning class in javascript and the below code doesn't seem to work 当用户按下表单上的提交时如何显示特定消息? - How to show specific message when user presses submit on form?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM