2011-04-22 58 views
1

我想要使用jQuery禁用所有在表之外的另一個鏈接點擊動態創建的表的所有<a>標記。由於表格是動態創建的,因此我的點擊事件無法在表格中找到<a>標籤。什麼可能是解決方案?我試過$("#tableId a").removeAttr("href")但這不起作用。使用jQuery刪除錨點標記的鏈接

回答

0
$("#tableId a").live('click',function(e){ 
e.preventDefault(); 
return false; 
}); 
+0

沒有理由你'的preventDefault()''_and_返回false;' - 但這無論如何都不會工作,因爲OP說該表是動態創建的。 – 2011-04-22 15:40:56

1

由於是動態創建的表,使用.live()

$('#outerLink').one('click', function() 
{ 
    $("#myTable a").live('click', function() 
    { 
     return false; 
    }); 
}); 
0

由於正在創建表動態,你必須綁定live這樣的活動:

$("#tableID a").live("click", function(e){ 
    e.preventDefault(); 
    return; 
}); 
0

你也可以只將disabled屬性添加到鏈接。

$("#tableID").find("a").attr("disabled","disabled"); 
0

在jquery 1.7及更高版本中,Live()方法已被棄用。請嘗試以下操作:

$("#tableId").on({ 
click: function(event){ $(this).removeAttr("href"); } 
},"a"); 

只要在頁面加載時存在#tableId。否則,你就需要去一個級別的東西,確實存在:

$(document).on({ 
click: function(event){ $(this).removeAttr("href"); } 
},"a");