使用class而不是id的keyup事件 [英] keyup events using class instead of id
本文介绍了使用class而不是id的keyup事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我有2个文本框,不使用id,我如何确定哪个文本框触发keyup事件?
由于各种原因,我需要使用类而不是id,其中两个文本框的类名相同。
事实上,我可以在屏幕上使用相同的类名多次使用相同的文本框。 / p>
HTML看起来像这样
< div class = outer_div>
< input type =textclass =mytextbox/>
< div class =inner_div>< / div>
< / div>
< div class =outer_div>
< input type =textclass =mytextbox/>
< div class =inner_div>< / div>
< / div>
< div class =outer_div>
< input type =textclass =mytextbox/>
< div class =inner_div>< / div>
< / div>
解决方案
$( '.mytextbox')。keyup(function(event){
//使用事件
//使用$(this)来确定哪个元素触发此事件
});
If I have 2 textboxes, without using id's, how do I determine which textbox is firing off "keyup" events?
For various reasons I need to use classes instead of id's, where the class name is the same for both textboxes.
Infact, I could have the same textbox on the screen many times with the same class name.
The HTML looks something like this
<div class="outer_div">
<input type="text" class="mytextbox" />
<div class="inner_div"></div>
</div>
<div class="outer_div">
<input type="text" class="mytextbox" />
<div class="inner_div"></div>
</div>
<div class="outer_div">
<input type="text" class="mytextbox" />
<div class="inner_div"></div>
</div>
解决方案
$('.mytextbox').keyup(function(event){
// play with event
// use $(this) to determine which element triggers this event
});
这篇关于使用class而不是id的keyup事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文