Jquery无法禁用事件

时间:2014-06-28 14:32:31

标签: javascript jquery

这里的第一个问题,我现在已经尝试了很多方法,但仍然无法让它做我想要的。 这是我的当前代码:

    $('#viewPortButtonForth').click(function()
    {
        state++;
        switcher();
        $('#viewPortButtonForth').prop('disabled',true);
        $('#viewPortButtonForth').attr("disabled", "disabled");
    });

更好的描述:

我想在单击后禁用.click事件,只是在一秒钟后再次启用它。

<div id="viewPortButtonForth"> <img src="stuff/back_and_forth.png"> </div>

基本上我想要的是:

    $('#viewPortButtonForth').click(function()
    {
        state++;
        switcher();
        disable the click event on itself
        wait 1000ms
        enable the click event again
    });

1 个答案:

答案 0 :(得分:1)

你可以这样做,

function test()
{
    state++;
    switcher();
    $(this).off("click");
    setTimeout(function(){  $(this).on('click',test) },1000);
}

$('#viewPortButtonForth').on('click',test);