我有一个链接,可以通过 ajax 加载一些内容。
我的问题是,我不想删除文本“加载评论”,我只想不允许在此类中进行更多点击。
<a href="javascript:;" class="showcomments" id="'.$idf.'">Load comments</a>
查询
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 的 one()
函数
$(".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.
关于javascript - 允许在 JQUERY 类中单击一次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37579315/