0

我对这个问题束手无策

这里的想法是防止链接工作,直到脚本完成其工作并再次启用链接。

我正在使用现场,不打算改变它。下面的脚本可以在没有 live 的情况下工作,但不能在 live 的情况下工作。你能看出为什么吗?

$(document).ready(function () {
    $('.user').live('click',function() { // All works well if live is removed.
    //But I need live, since things change and there's a lot of old code using it.
        console.log('Invoked');
        // Do anything to disable the link
        $('.user').unbind('click'); // Does not work
        //$('.user').off('click'); // Does not work either

       //Once the script is done with its ajax work, enable it again
         //$('.user').bind('click');
        //$('.user').on('click');

    });

});


<div class="container">
    <div><i class="icon-add user"></i></div>
    <div><i class="icon-add user"></i></div>
    <div><i class="icon-add user"></i></div>
    <div><i class="icon-add user"></i></div>
</div>
4

2 回答 2

1

你试过使用 .one() 吗?

$('.user').one('click',function() { ...
于 2013-11-14T08:15:56.793 回答
-1

live()函数从 jQuery 1.7 被弃用:看看这个页面

您应该更好地使用on()功能:文档

于 2013-11-14T08:17:40.180 回答