2013-03-29 19 views
0

得到Atrribute我有如下表如何從表

<table> 
    <thead> 
    <tr> 
     <th col="value2"></th> 
    </tr> 
    </thead> 
    <tbody> 
    <tr id="value1"> 
     <td></td> 
     </tr> 
    </tbody 
<table> 

我用下面從<tr>

"row_id": this.parentNode.getAttribute('id') 

得到「值1」我試圖用下面讓山坳值從<th>但它返回一個空值。

"colName": this.getAttribute('col') 

如何正確從<th>獲取col屬性值?

回答

1

試試這個DOM功能:

document.getElementsByTagName("th")[0].getAttribute("col"); 
+0

感謝您的。有沒有可能用它來指定陣列號? – Rhys

0
$(document).ready(function() { 
     console.log($('table thead tr th').attr('col')); 

}); 

這會給第一TR你可以做的是檢查的行數或使用foreach循環

+0

謝謝,但那也返回一個空值。 – Rhys

+0

我已更改代碼PLZ檢查 – Biswajit

+0

謝謝,該工程的第一個值,但如果我有多個的它將仍然只會返回第一個值。 – Rhys