BACKSPACE按钮需要禁用 [英] BACKSPACE button need to disable

查看:90
本文介绍了BACKSPACE按钮需要禁用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能存在重复:

如何禁用使用jQuery的文本框以外的退格符


我想禁用BACKSPACE按钮,除非它在TEXT字段中。



我使用下面的代码,但它阻止退格功能包括文本字段。仅限于TEXT字段..



请帮助解决......

  $(document).on(keydown,processKeyEvents); 
$(document).on(keypress,processKeyEvents);

函数processKeyEvents(event){
// Backspace
if(event.keyCode == 9){
// myTextBox是有效文本框的ID
if($(*:focus)!= $(#myTextBox)){
event.preventDefault();




解决方案

你不能比较那些jQuery对象,而你只需要一个关键事件,并且退格键不是键9。 (e.keyCode === 8&&!$('#myTextBox')pre($ document $) ).is(':focus')){
e.preventDefault();
}
});


Possible Duplicate:
How to disable backspace except textbox using jQuery

I want to disable BACKSPACE button except when its in TEXT field.

I am using following code but it prevent backspace functionality include text field.. BACKSPACE should work for TEXT field only..

Please help this out...

$(document).on("keydown", processKeyEvents);
$(document).on("keypress", processKeyEvents);

function processKeyEvents(event) {
    // Backspace
    if (event.keyCode == 9) {
        // myTextBox is id of the valid textbox
        if ($("*:focus") != $("#myTextBox")) {
            event.preventDefault();
        }
    }
} 

解决方案

You can't compare jQuery objects like that, and you only need one key event, and backspace is not key 9.

$(document).on('keydown', function(e) {
    if(e.keyCode === 8 && !$('#myTextBox').is(':focus')) {
        e.preventDefault();
    }
});

这篇关于BACKSPACE按钮需要禁用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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