2013-04-04 181 views
0

我的頁面中有錨定標記。並且爲某些功能編寫.click()事件, 我希望禁用頁面加載操作,並啓用某些按鈕單擊操作。錨定標記的Jquery綁定和解除綁定事件

爲了防止動作我可以使用解除綁定(「點擊」)。但無法綁定爲.Bind(「click」)需要函數名稱。

請幫助在頁面加載我

回答

2

而是擔心分離和重新連接事件,你可以存儲hrefdata-屬性然後設置href#的。點擊啓用按鈕後,我們可以恢復href

jsFiddle

HTML

<a href="http://www.google.com">Google</a> 
<button id="enable">Enable</button> 

JS

$(document).ready(function() { 
    $('a').each(function() { 
     disableAnchor($(this)); 
    }); 
    $('#enable').click(function() { 
     $('a').each(function() { 
      enableAnchor($(this)); 
     }); 
    }); 
}); 
function disableAnchor(a) { 
    a.attr('data-href', a.attr('href')); 
    a.attr('href', '#'); 
} 
function enableAnchor(a) { 
    a.attr('href', a.attr('data-href')); 
} 
0

使用

$(function(){ 
    $("a").removeAttr('onclick'); 
});