-1

Backspace/Delete 在Mozilla Firefox中无法用于 Jquery 字母数字验证。

<input type="text" id="myTextBox" />
$("#myTextBox").bind("keypress", function(event) { 
    var charCode = event.which;

    var keyChar = String.fromCharCode(charCode); 
    return /[a-zA-Z0-9]/.test(keyChar); 
});

点击这里进行演示

4

1 回答 1

2

使用此代码

<input type="text" id="myTextBox" />
$("#myTextBox").bind("keypress", function(event) { 
        var charCode = event.which;

        if(charCode == 8 || charCode == 0)
        {
             return;
        }
        else
        {
            var keyChar = String.fromCharCode(charCode); 
            return /[a-zA-Z0-9]/.test(keyChar); 
        }
    });
于 2013-03-12T11:24:15.877 回答