2014-09-27 90 views
0

我有細胞與<td>標籤。
每個單元格都有行號和列號。
細胞的語法示例與row = 0col = 0如何獲取​​根據特定屬性的值標記

<td class row="0" col="0"> 
<span>1</span> 
</td> 

我要根據具體的屬性值來獲得標記。
例如,我想它有第一單元:行= 0和col = 0
我想:

$("td").attr("row", 0).attr("col", 0) 

,但其覆蓋的屬性值:
enter image description here

我如何根據特定屬性的值獲取標籤? (我更喜歡用jQuery)

+0

$( 「TD [行= 0] [COL = 0]」) – Kalyan 2014-09-27 13:42:06

+0

不補的隨機屬性,使用自定義的數據,而不是屬性。例如:'data-row =「1」' – j08691 2014-09-27 13:43:09

回答

1

見我的評論以上。但要做到你在jQuery的要求是什麼,用途:

$('td[row="0"][col="2"]').html() 
2

vanilla,你可以使用node.querySelectornode.querySelectorAllselector which matches these attributes,例如

function getTds(row, col) { // NodeList 
    return document.querySelectorAll('td[row="' + row + '"][col="' + col + '"]'); 
} 

那麼對於4排山坳0

var td = getTds(4, 0)[0]; // HTMLTableCellElement or undefined 
+0

_row_和_col_是非標準的,所以我不想假設這些將是唯一的 – 2014-09-27 13:47:33

相關問題