[英]can we use the jquery one() for attribute class having multiple elements
What I am trying to do is, I have different DIV
element having different ID
's and same class
我想做的是,我有不同的
DIV
元素,具有不同的ID
和相同的class
What I know is: 我所知道的是:
$(id).one()
and 和
$(class).one()
it work as given in the doc here : Attach a handler to an event for the elements. 它的工作方式如doc 此处所示 :将处理程序附加到元素的事件。 The handler is executed at most once per element per event type.
每个事件类型的每个元素最多只能执行一次处理程序。
What I want: 我想要的是:
$(class).one()
The handler is executed at most once per ID
ie once per DIV element per event type. 该处理程序每个
ID
最多执行一次,即每种事件类型的每个DIV元素执行一次。 and not only once for a class? 不仅一次上课?
Solution I know: 我知道的解决方案:
$(id1).one()
$(id2).one()
$(id3).one() ...
write it as many time as ID's I have which I don't want
写下
I don't want
ID的次数
is it possible? 可能吗?
Thanks in advance! 提前致谢!
not sure what are you asking for . 不知道你在问什么。 but
most once per element per event type
class selector should work 但
most once per element per event type
类选择器most once per element per event type
只能工作一次
<div class="click">click1</div>
<div class="click">click2</div>
$('.click').one("click",function(){
alert('clicked');
})
Im guessing you want to add a one()
to all element of that class, but each of those items may only be clicked once: 我想您想向该类的所有元素添加一个
one()
,但是这些项中的每一项只能被单击一次:
<div class="click">click1</div>
<div class="click">click2</div>
$('.click').one("click",function(){
$(this).off('click'); // torn off click event
alert( 'This element will not alert this message again' );
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.