我有一棵左树。它的结构就像这样
MainCategory Category1 Subcategory1 Subcategory2 Category2 Subcategory3 Subcategory4 Subcategory5 Category3 . .. etc like that
如果用户单击任何MainCategory / Category / Subcategory,我需要禁用/防止重复/多次单击同一链接,直到结果出现。我怎么能用jquery做到这一点?
答案 0 :(得分:2)
如果您使用jQuery 1.7,则可以使用off()和on()功能
示例:
var foo = function () {
// code to handle some kind of event
};
// ... now foo will be called when paragraphs are clicked ...
$("body").on("click", "p", foo);
// ... foo will no longer be called.
$("body").off("click", "p", foo);
示例:
var foo = function () {
// code to handle some kind of event
};
// ... now foo will be called when paragraphs are clicked ...
$("body p").bind("click", foo);
// ... foo will no longer be called.
$("body p").unbind("click");
答案 1 :(得分:1)
可能只是使用一个类来检查它是否已被点击 如果单击,则不执行,并在成功和失败时删除该类。
原型 -
$('.selector').click(function(){
if(!$(this).hasClass('someclass')){
$(this).addClass('someclass');
$.ajax({
url: "test.html",
success: function(){
$(this).removeClass("someclass");
},
error: function(){
$(this).removeClass("someclass");
}
});
}
})