手机
当前位置:查字典教程网 >编程开发 >Javascript教程 >Javascript遍历Html Table示例(包括内容和属性值)
Javascript遍历Html Table示例(包括内容和属性值)
摘要:1:遍历并输出Table中值functionf(){vart=document.getElementById("tb").childNode...

1: 遍历并输出Table中值

<table id="tb"> <tr> <td></td> </tr> <tr> <td></td> </tr> </table> function f() { var t=document.getElementById("tb").childNodes.item(0); for(var i=0;i< t.childNodes.length;i++) { for(var j=0;j<t.childNodes(i).childNodes.length;j++) { alert(t.childNodes(i).childNodes(j).innerText); } } }

2: 遍历Table,读取CheckBox状态和其他Column值

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Untitled Page</title> </head> <body onload="f()"> <script type="text/javascript"> function f() { var t=document.getElementById("tb").childNodes.item(0); for(var i=0;i< t.childNodes.length;i++) { alert(t.childNodes(i).firstChild.firstChild.nodeValue); alert(t.childNodes(i).childNodes[1].firstChild.checked); } } </script> <table id="tb"> <tr> <td> 1234</td> <td> <input type="checkbox" /></td> <td> </td> </tr> <tr> <td> 2234</td> <td> <input type="checkbox" checked="CHECKED" /></td> <td> </td> </tr> <tr> <td> 3234</td> <td> <input type="checkbox" /></td> <td> </td> </tr> </table> </body> </html>

【Javascript遍历Html Table示例(包括内容和属性值)】相关文章:

JavaScript获取并更改input标签name属性的方法

Javascript实现div的toggle效果实例分析

JavaScript中的Math.LN2属性用法详解

javascript的事件描述

Javascript的IE和Firefox兼容性汇编

JavaScript获得指定对象大小的方法

javascript实现Table间隔色以及选择高亮的方法

JavaScript判断图片是否已经加载完毕的方法汇总

Javascript中prototype属性实现给内置对象添加新的方法

javascript搜索框效果实现方法

精品推荐
分类导航