2014-09-27 92 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

相关问题