每次事件循环时单击Jquery

时间:2013-07-05 09:26:43

标签: jquery html5

我创建的代码只显示了事件点击等功能。

我正面临处理此事件的困难。

任何人都可以帮助我,我犯了哪个错误。因为每当我点击事件时它总是同时重复。假设我第一次点击警报只出现一次,当我第二次点击警报将显示两次时。

$(document).ready(function () {
  $('#button').click(function (e) { // Button which will activate our modal
    $('#modal').reveal({ // The item which will be opened with reveal
      animation: 'fade', // fade, fadeAndPop, none
      animationspeed: 600, // how fast animtions are
      closeonbackgroundclick: true, // if you click background will modal close?
      // the class of a button or element that will close an open modal
      dismissmodalclass: 'close'
    });

    $("#gag").click(function () {
      alert('This event will trigger only once!');
    });
    $("#fug").click(function () {
      alert('This event will trigger only twice!');
    });
  });
});

1 个答案:

答案 0 :(得分:1)

$(document).ready(function() {
    $('#button').click(function(e) { // Button which will activate our modal
        $( "#gag" )
            .unbind()
            .click(
                function() { 
                    alert('This event will trigger only once!'); 
                });
        $( "#fug" )
            .unbind()
            .click(
                function() { 
                    alert('This event will trigger only twice!'); 
                });
    });
});

这将首先unbind()然后bind(),因此不会重复您的活动

相关问题