【问题标题】:The event is not stop the firing in jquery该事件不会停止在 jquery 中的触发
【发布时间】:2015-08-01 06:20:17
【问题描述】:

我已经使用了 return false preventDefault stoppropogation,但是当数据为 1

  $(document).on('click','.lunch_out',function(e){ //lunch out
            var object = this;

            $.post('attendance_action.php',{'action':'check_time'},function(data){ //check the lunch time reached or not
                alert(data);
                if ($.trim(data) == '1') {
                    alert();
                    bootbox.alert("Sorry! Lunch time Over.");
                    $(object).remove();
                   // e.stopPropagation();
                    e.preventDefault();
//return false;
                }
            });
            $.post('attendance_action.php',{'action':'lunch_out'},function(data){
                window.location.reload();
            });
            e.preventDefault();
        });

【问题讨论】:

    标签: jquery preventdefault stoppropagation


    【解决方案1】:

    你应该设置else,这样其他帖子才会在数据不是1时运行

    $(document).on('click', '.lunch_out', function(e) { //lunch out
      var object = this;
    
      $.post('attendance_action.php', {
        'action': 'check_time'
      }, function(data) { //check the lunch time reached or not
        alert(data);
        if ($.trim(data) == '1') {
          alert();
          bootbox.alert("Sorry! Lunch time Over.");
          $(object).remove();
        } else { // your else 
          $.post('attendance_action.php', {
            'action': 'lunch_out'
          }, function(data) {
            window.location.reload();
          });
        }
      });
      e.preventDefault();
    });
    

    【讨论】:

      猜你喜欢
      • 2011-01-22
      • 2011-08-25
      • 1970-01-01
      • 1970-01-01
      • 2021-07-14
      • 1970-01-01
      • 2020-02-08
      • 2014-09-18
      相关资源
      最近更新 更多