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

时间:2014-10-21 13:00:22

标签: 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 */        

});

1 个答案:

答案 0 :(得分:2)

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

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