在JQUERY课程中只需一次点击即可 [英] Allow just one click in class JQUERY
问题描述
我的问题是,我不想删除文本加载评论,我只是希望不要让这个班级获得更多点击。
< a href =javascript :; class =showcommentsid ='。$ idf。'>加载注释< / a>
Jquery
var Progressajax = false;
$(function(){
$(。showcomments)。click(function(){
if(Progressajax)return;
Progressajax = true;
var element = $(this);
var id = element.attr(id);
Progressajax = false;
alert ok);
$(data).hide()。prependTo('。varload'+ id).fadeIn(1000);
// $(element).remove();
$(element).removeAttr(href);
$(element).removeClass('showcomments');
});
});
我只想第一次看到OK。如何删除这个类?
$(element).removeClass('showcomments');
这不工作...
使用jQuery的一()
函数
code> $(。showcomments)。one(click,function(){
http://www.w3schools.com/jquery/event_one.asp
one()方法为所选元素附加一个或多个事件处理程序,并指定在事件发生时运行的函数。
当使用one()方法时,事件处理函数只对每个元素运行ONCE。
I have a link that will load via ajax some content.
My problem is, I don't want to remove the text "Load comments", I just want to not allow more clicks in this class.
<a href="javascript:;" class="showcomments" id="'.$idf.'">Load comments</a>
Jquery
var Progressajax = false;
$(function() {
$(".showcomments").click(function(){
if(Progressajax) return;
Progressajax = true;
var element = $(this);
var id = element.attr("id");
Progressajax = false;
alert("ok");
$(data).hide().prependTo('.varload'+id).fadeIn(1000);
//$(element).remove();
$(element).removeAttr("href");
$(element).removeClass('showcomments');
});
});
I just want to see OK the first time. How can I remove this class?
$(element).removeClass('showcomments');
This is not working...
Use jQuery's one()
function
$(".showcomments").one("click", function() {
http://www.w3schools.com/jquery/event_one.asp
The one() method attaches one or more event handlers for the selected elements, and specifies a function to run when the event occurs.
When using the one() method, the event handler function is only run ONCE for each element.
这篇关于在JQUERY课程中只需一次点击即可的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!