按钮单击事件多次触发

时间:2017-03-25 12:37:20

标签: javascript jquery

我有一个从php文件回显的按钮。 当我点击该按钮时,它会多次触发。为什么它表现得那样?

我做了一些我在stackoverflow中找到的解决方案,但是它们没有用。 有任何建议和更正吗?

$(document).on('click','#reserve',function(){
      if (myclid != '0') {
        if (ll.charAt(0)=='b') {
            alert(lnk2);
            $.ajax({
              url: "reserve_func.php",
              method: "POST",
              data: {reserve_id:random_numbers, myclid:myclid, myclient:myclient, lnk2:lnk2, clid:clid},
              success: function(data) {
                  if (data == 'true') {

                    getResDate();
                  } else if (data== 'exceeded') {

                      pop();
                      $('#notice').html('Client <b style="text-transform: capitalize;">'+myclient +'</b> has two (2) lots that were still reserved and are not yet paid.');
                  }  else {

                      pop();
                      $('#notice').html(data);
                  }  
              }
            });
        }
      } else if (myclid=='0') {

        $('#pop_bg').fadeIn('fast');
        $('#pop_c').slideDown('fast');
        $('#notice').fadeIn('fast');
        $('#notice').html('Please select a client!');
      } else {

        $('#pop_bg').fadeIn('fast');
        $('#pop_c').slideDown('fast');
        $('#notice').fadeIn('fast');
        $('#notice').html('Please add your client first! Click <a href="profile.php">here</a> and then select <b>My client(s)');
      }
});

1 个答案:

答案 0 :(得分:-1)

请检查一下。

&#13;
&#13;
$( "#reserve" ).on( "click", function( event ) {
	event.preventDefault();
	var install = $('#gt').val();
      if (myclid != '0') {
        if (ll.charAt(0)=='b') {
            alert(lnk2);
            $.ajax({
              url: "reserve_func.php",
              method: "POST",
              data: {reserve_id:random_numbers, myclid:myclid, myclient:myclient, lnk2:lnk2, clid:clid},
              success: function(data) {
                  if (data == 'true') {

                    getResDate();
                  } else if (data== 'exceeded') {

                      pop();
                      $('#notice').html('Client <b style="text-transform: capitalize;">'+myclient +'</b> has two (2) lots that were still reserved and are not yet paid.');
                  }  else {

                      pop();
                      $('#notice').html(data);
                  }  
              }
            });
        }
      } else if (myclid=='0') {

        $('#pop_bg').fadeIn('fast');
        $('#pop_c').slideDown('fast');
        $('#notice').fadeIn('fast');
        $('#notice').html('Please select a client!');
      } else {

        $('#pop_bg').fadeIn('fast');
        $('#pop_c').slideDown('fast');
        $('#notice').fadeIn('fast');
        $('#notice').html('Please add your client first! Click <a href="profile.php">here</a> and then select <b>My client(s)');
      }
});
&#13;
&#13;
&#13;