开发者

How to get a Javascript routine to NOT act if it's in a text box?

I've got a simple page, and in that page runs a simple jquery keypress routine to catch clicks of the numbers 1 to 9 (has to be that to pass RNIB accessibility test).

And in that page is a form, which can have numbers entered as part of a postcode.

http://find.talking-newspapers.co.uk/result.php?addressInput=kingston

Scroll to the bott开发者_如何转开发om, try typing 8 or 9 for example. The text is entered, but it also acts on the keypress. Expected, but not good.

I'm aware of various things like document.getElementById, but I can't figure out how to put these together to ensure that while the cursor is in the text input box, it doesn't act out the keypress catcher.


The target property of the event object (the parameter to the handler function) will tell you which element actually generated the event.

You need to check whether e.target is an <input> element, like this:

if ($(e.target).is(':input'))
    return;
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜