$("a").click(function(event){
  event.preventDefault();
});
preventDefault() 方法阻止元素发生默认的行为(例如,当点击提交按钮时阻止对表单的提交)。那么我想 不停止event事件的语句应该怎样写,想继续执行,或者说是允许click的event事件?因为我要写一个if(){}else{}语句。
$("a").click(function(event){
 这里应该怎么写????
});

解决方案 »

  1.   

    if(。。){$("a").click(function(event){
       event.preventDefault();
    });
    }else{$("a").click(function(event){
       //方法体
    });
    }
      

  2.   

    补充源码 如下!function checkyzm()
    {
    var yzm=$("#yzm").val();
    $.get("inc/checkyzm.php?yzm="+yzm, function(data)
    {
      if($.trim(data)=="1")
      {
      $("#checkyzm").html("验证码输入正确");
      $("#yzm").removeClass("redborder");                           $(document).ready(function()
     {
     $("#button2").click(function(event)
    {
    这里应该怎样写????? }
      );
     }


      );   return true;
      }else{
      $("#checkyzm").html("验证码输入错误");
       /* document.getElementById("button2").disabled="disabled";*/
     $(document).ready(function()
     {
     $("#button2").click(function(event)
    {
    event.preventDefault();
    }
      );
     }


      );
          $("#yzm").addClass("redborder");

      return false;
     
      }
      
      }); 
    }
      

  3.   

    自己解决了同样也谢谢楼上的 p2227 给你满分
    function checkyzm()
    {
    var yzm=$("#yzm").val();
    $.get("inc/checkyzm.php?yzm="+yzm, function(data)
    {
      if($.trim(data)=="1")
      {
      $("#checkyzm").html("验证码输入正确");
      $("#yzm").removeClass("redborder");
      /*document.getElementById("button2").disabled="";*/
      
      $(document).ready(function()
     {
     $("#button2").unbind("click").click(function(event)
    {
    return true;  //对的时候用true; }
    );
      
     
    /*  $("#test2").unbind('click').click(function() {                        alert("click解除绑定执行" + k++ + "次");                    });*/
     
     
     }


      );
      
      
      
      return true;
      }else{
      $("#checkyzm").html("验证码输入错误");
       /* document.getElementById("button2").disabled="disabled";*/
     $(document).ready(function()
     {
     $("#button2").click(function(event)
    {
    return false;  //错的时候用false
    }
      );
     }


      );
          $("#yzm").addClass("redborder");

      return false;
     
      }
      
      }); 
    }