欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

js中獲取 table節(jié)點各tr及td的內(nèi)容簡單實例

 更新時間:2016年10月14日 20:53:20   投稿:jingxian  
下面小編就為大家?guī)硪黄猨s中獲取 table節(jié)點各tr及td的內(nèi)容簡單實例。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
<table id="tb1" width="200" border="1" cellpadding="4" cellspacing="0">
    <tr>
        <td height="25">第一行</td>
    </tr>
    <tr>
        <td height="25">第二行</td>
    </tr>
    <tr>
        <td height="25">第三行</td>
    </tr>
    <tr>
        <td height="25">第四行</td>
    </tr>
		 <tr>
        <td height="25"><input type="button" name="getTableContent" value="獲得表格內(nèi)容" onclick="getTableContent(this)"></td>
    </tr>
</table>

如上所示代碼,按鈕點擊事件中傳入this對象,此對象就是按鈕本身。通過以下方法測試獲取表格的數(shù)據(jù)

<script language="javascript">
    function getTableContent(node) {
// 按鈕的父節(jié)點的父節(jié)點是tr。
		  var tr1 = node.parentNode.parentNode;
			alert(tr1.rowIndex);
			alert(tr1.cells[0].childNodes[0].value); //獲取的方法一
alert(tr1.cells[0].innerText); 
// 通過以下方式找到table對象,在獲取tr,td。然后獲取td的html內(nèi)容
        var table = document.getElementById("tb1");//獲取第一個表格
		
        var child = table.getElementsByTagName("tr")[rowIndex - 1];//獲取行的第一個單元格
				
        var text = child.firstChild.innerHTML;
        window.alert("表格第" + rowIndex + "的內(nèi)容為: " + text);
    }
</script>

以上就是小編為大家?guī)淼膉s中獲取 table節(jié)點各tr及td的內(nèi)容簡單實例全部內(nèi)容了,希望大家多多支持腳本之家~

相關文章

最新評論