如何使用javascript或jquery在html页面中禁用esc键 [英] How to disable esc key in html page using javascript or jquery

查看:1130
本文介绍了如何使用javascript或jquery在html页面中禁用esc键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在HTML页面中禁用ESC键。我该怎么做?

I want to disable the ESC key in an HTML page. How can I do this?

我有一个表格显示为jQuery UI Dialog。如果我单击ESC键,表单将关闭。我想禁用它。

I have a form which is appearing as jQuery UI Dialog. Here if I click the ESC key, the form will close. I want to disable that.

推荐答案

浏览器( Firefox Chrome ...)通常将 Esc 键绑定到停止加载当前页面操作。任何其他行为都需要使用JavaScript进行专门编码。

Browsers (Firefox, Chrome...) normally bind the Esc key to the "stop loading current page" action. Any other behaviour needs to be specifically coded with JavaScript.

jQuery UI对话框中有一个 closeOnEscape 设置。只需将其设置为 false

The jQuery UI Dialog has a closeOnEscape setting. Just set it to false:


  • 使用closeOnEscape初始化对话框指定的选项:

  • Initialize a dialog with the closeOnEscape option specified:

$( ".selector" ).dialog({ closeOnEscape: false });


  • 在init之后获取或设置closeOnEscape选项:

  • Get or set the closeOnEscape option, after init:

    //getter
    var closeOnEscape = $( ".selector" ).dialog( "option", "closeOnEscape" );
    //setter
    $( ".selector" ).dialog( "option", "closeOnEscape", false );
    


  • 这篇关于如何使用javascript或jquery在html页面中禁用esc键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆