gpt4 book ai didi

javascript - 允许在 JQUERY 类中单击一次

转载 作者:行者123 更新时间:2023-11-30 07:22:39 25 4
gpt4 key购买 nike

我有一个链接,可以通过 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');

这不工作...

http://jsfiddle.net/qsn1tuk1/

最佳答案

使用 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/32616022/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com