如果满足某些条件id,则退出bind('click',function(event){})

时间:2015-11-27 19:50:08

标签: jquery

我需要在某些条件下退出 bind('click',function(event){})块。 event.preventDefault()或return false似乎没有帮助。如果有人可以告诉我正在发生的事情将会有很大帮助。在此先感谢和问候。

Sukalyan

jquery如下:

$('a').bind('click', function (e) { 

            if (/#enter/.test(this.href)) { //exit bind.click
                e.preventDefault();
                //return false;
            }

            if (/#edit/.test(this.href)) { //exit bind.click
                e.preventDefault();
                //return false;
            }

            $('.content:visible').hide();
            $(this.hash).show();
            e.preventDefault();
        });

2 个答案:

答案 0 :(得分:0)

只需有条件地执行事件处理代码:

hmac = crypto.createHmac('sha256', master);
hmac.update("hmac");
var hmacKey = hmac.digest();

// TODO encrypt

hmac = crypto.createHmac('sha256', hmacKey);
hmac.update(ciphertext);
var authenticationTag = hmac.digest();

答案 1 :(得分:0)

我无法理解你的观点,所以有两种方式

1st:阻止并对所有链接执行操作但不与href链接以#enter或#edit

开头
$('a:not([href^="#enter"]):not([href^="#edit"])').on('click',function(e){
      $('.content:visible').hide();
      $(this.hash).show();
      e.preventDefault();
});

第二:阻止并为href的链接执行操作以#enter或#edit

开头
$('a[href^="#enter"], a[href^="#edit"]').on('click',function(e){
          $('.content:visible').hide();
          $(this.hash).show();
          e.preventDefault();
});