开发者

Trouble adding an onkeypress event to a textbox outside of the input tag

开发者 https://www.devze.com 2023-03-28 21:59 出处:网络
I need to add an event to a text box without modifying the input tag itself.I created a function which will check to make sure only letters are entered and not allow numbers or symbols.I have to code

I need to add an event to a text box without modifying the input tag itself. I created a function which will check to make sure only letters are entered and not allow numbers or symbols. I have to code for this and it is functional... when ins开发者_StackOverflow社区erted inside of the input tag, I am having trouble in adding this event elsewhere in my code. Any help is much appreciated.

Thanks in advance,


Get all the inputs that you are interested in monitoring. Then subscribe each of them to a function and your event.

QuirksMode talks about traditional event mapping here and also has links to W3C standard events.

So gather all your inputs and then attach your event to them

Pseudocode:
var elementArray = getAllInputElements();
for (var element in elementArray) {
    element.onclick = myfunction;
}
0

精彩评论

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

关注公众号