javascript - Jquery 无法禁用事件

标签 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
    });

最佳答案

你可以这样做,

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

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

关于javascript - Jquery 无法禁用事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24467826/

相关文章:

javascript - 使用 Angular 时隐藏 API key (也许在环境变量中?)

javascript - 使用 JavaScript 获取 DIV 的内容

javascript - jquery函数在提交后继续运行

javascript - 单击后导航栏中指向#anchors 的链接未关闭

javascript - 将 eonasdan-datetimepicker 附加到动态创建的元素会返回 "relative positioned container"错误

javascript - 按名称删除 cookie?

javascript - 移动设备未注册 OneSignal 可能是什么原因?

jquery - 表格单元格在文本显示/隐藏时移动

javascript - 如何使用单击事件切换元素中的文本

javascript - 未捕获的类型错误 : Cannot use 'in' operator to search for '161' in