开发者

jQuery KeyFilter Plugin Problem

Using keyfilter plu开发者_运维问答gin for jQuery, and all seems to be fine apart from one problem.

I am using a regular expression to filter the element.

$('#nameVal').keyfilter(/[0-9a-zA-Z]/);

The odd thing is, this is not only allowing alpha-numeric characters but it is also allowing '(' to be entered. In fact, it doesn't matter what expression I pass to the keyfilter, I can't stop '(' being allowed in the textbox.

Has anyone else experienced this problem and is there a solution?


I found the problem.

The isSpecialKey function in the KeyFilter plugin returns true if the keycode is 40, which is the keycode for '('. This means that the test is never performed on the character.

var isSpecialKey = function(e)
{
    var k = e.keyCode;
    var c = e.charCode;
    return k == 9 || k == 13 || /*(k == 40 && (!$.browser.opera || !e.shiftKey)) ||*/ k == 27 ||
        k == 16 || k == 17 ||
        (k >= 18 && k <= 20) ||
        ($.browser.opera && !e.shiftKey && (k == 8 || (k >= 33 && k <= 35) || (k >= 36 && k <= 39) || (k >= 44 && k <= 45)))
        ;

    };

Commenting out the bit of code as I have above fixes the problem. Not entirely sure what effect this will have in other browsers, but it works in IE8 and Chrome.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜