我有一个链接,可以通过 ajax 加载一些内容.
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');
});
});
我只想第一次看到OK.如何删除此类?
I just want to see OK the first time. How can I remove this class?
$(element).removeClass('showcomments');
这不行……
http://jsfiddle.net/qsn1tuk1/
使用jQuery的one()函数
Use jQuery's one() function
$(".showcomments").one("click", function() {
http://www.w3schools.com/jquery/event_one.asp
one() 方法为所选元素附加一个或多个事件处理程序,并指定事件发生时要运行的函数.
The one() method attaches one or more event handlers for the selected elements, and specifies a function to run when the event occurs.
当使用 one() 方法时,事件处理函数只对每个元素运行一次.
When using the one() method, the event handler function is only run ONCE for each element.
这篇关于只允许在 JQUERY 类中单击一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
在 Angular 2/Typescript 中使用 IScrollUse IScroll in Angular 2 / Typescript(在 Angular 2/Typescript 中使用 IScroll)
Anime.js 在 Ionic 3 项目中不起作用anime.js not working in Ionic 3 project(Anime.js 在 Ionic 3 项目中不起作用)
Ionic 3 - 使用异步数据更新 ObservableIonic 3 - Update Observable with Asynchronous Data(Ionic 3 - 使用异步数据更新 Observable)
Angular 2:在本地 .json 文件中找不到文件Angular 2: file not found on local .json file(Angular 2:在本地 .json 文件中找不到文件)
在 Ionic 2 中,如何创建使用 Ionic 组件的自定义指In Ionic 2, how do I create a custom directive that uses Ionic components?(在 Ionic 2 中,如何创建使用 Ionic 组件的自定义指令?)
将 ViewChild 用于动态元素 - Angular 2 &离子2Use ViewChild for dynamic elements - Angular 2 amp; ionic 2(将 ViewChild 用于动态元素 - Angular 2 amp;离子2)