我在網頁上有以下鏈接元素。 如何使用jQuery禁用此功能?似乎設置disabled屬性不會禁用它。禁用jQuery中的鏈接元素,然後啓用它
<A style="COLOR: black" href="javascript:__doPostBack('GridViewWithLinkqToSQL','Page$20')">20</A>
EDIT 1:ANSWER(與一個全功能的示例頁面代碼)
最後,我能夠啓用/禁用鏈路。要啓用簡單附加的事件的默認操作被禁用的點擊處理程序,並啓用刪除相同的點擊處理程序。在我的代碼下面,Link1將打開雅虎主頁,而Link2將顯示一個JavaScript錯誤,當這兩個鏈接都啓用時。
帶必要javascript/jQuery的Html頁面代碼如下。使用這種方法,您可以啓用/禁用div中的多個超鏈接(如在網格控件中)。以下是指向視頻的鏈接,其中會顯示禁用和啓用鏈接非常有用的情況:Disable all hyperlinks within a GridView during AJAX Postback。您會在視頻中注意到,當用戶點擊列標題鏈接或頁碼鏈接時,它不會執行任何操作,這是我們在發生長AJAX回發並且用戶開始不耐煩地點擊鏈接時想要的內容。
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Enable/Disable Links</title>
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
</head>
<body>
<div id="div1">
<a href="https://www.yahoo.com">Link1</a>
<a style="COLOR: black" href="javascript:__doPostBack('GridViewWithLinkqToSQL','Page$20')">Link2</a>
</div>
<input id="Button1" type="button" value="Disable Links" onclick="ToggleLinks(true);" />
<input id="Button2" type="button" value="Enable Links" onclick="ToggleLinks(false);" />
<script type="text/javascript">
function ToggleLinks(disabled) {
var div1 = $('#div1');
// div1.find("*").prop("disabled", disabled);
if (disabled) {
div1.find("a").each(function (i, element) {
$(this).click(function (e) {
e.preventDefault();
return false;
});
});
}
else {
div1.find("a").each(function (i, e) {
$(this).unbind("click");
});
}
}
</script>
</body>
</html>
disabled屬性適用於輸入元素。 – j08691
谷歌搜索'jquery禁用鏈接'給了我幾十個結果。 –
你檢查了[這些](http://stackoverflow.com/questions/970388/jquery-disable-a-link?rq=1)[questions](http://stackoverflow.com/questions/3788946/how-做-I-動態啓用 - 禁用鏈路與 - jquery的?RQ = 1)? – summea