javascript - 如何让 jquery/javascript 函数触发一次

标签 javascript jquery methods

我正在做一个基于 json 的多项选择测验。单击#next 按钮时,它会淡出并显示提交按钮。我注意到,如果我快速单击两次,有时计数变量会增加多次,并且当用户正确时变量分数也会增加。我怎样才能让它发射一次,停止发射然后再次使其可点击。有人告诉我 .off() jquery 方法,但不知道如何使用它。任何帮助将不胜感激。

/* report gives score after the last question=array length */
$('#next').on('mousedown',report);     

$('#next').on('click', function() {
    x++;  /* for selecting current question */
    count++;
    undo();  /* clears question area to load new one from json */
    placement();  /* brings in questions in json form */
    $(".alert").alert('close');  /* closes dialog */        

});

最佳答案

使用 jQuery 的 .one() 方法触发一次事件。

http://api.jquery.com/one/

关于javascript - 如何让 jquery/javascript 函数触发一次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26487379/

相关文章:

javascript - OnClick 不适用于我的元素

javascript - 拦截点击,进行一些调用,然后恢复点击之前应该执行的操作

javascript - 在 Node.js 中使用 Selectize

C#在方法中,参数前有一个@

javascript - 在 Dexie 迭代中使用 Promise

javascript - 拖放 + 捕捉六边形类似 Trello 的卡片

javascript - Firestore数据结构: Storing An Order in Firestore

jQuery - 与 one() 和 on() 函数的组合

c# 方法中的方法

java - Arraylist:方法不会打印数组中的最后一个元素