osh*_*nen 4 jquery jquery-selectors
如果我有2个文本框,而不使用id,我如何确定哪个文本框触发了"keyup"事件?
由于各种原因,我需要使用类而不是id,其中两个文本框的类名相同.
事实上,我可以使用相同的类名在屏幕上多次使用相同的文本框.
HTML看起来像这样
<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>
Run Code Online (Sandbox Code Playgroud)
$('.mytextbox').keyup(function(event){
// play with event
// use $(this) to determine which element triggers this event
});
Run Code Online (Sandbox Code Playgroud)