0

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

我在处理该事件时面临困难。

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

$(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!');
    });
  });
});
4

1 回答 1

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()因此不会重复您的事件

于 2013-07-05T09:32:59.743 回答