日期:2014-05-16 浏览次数:20340 次
<!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].childNodes[0].nodeValue); } } </script> <table id="tb"> <tr> <td style="width: 122px"> 1234</td> <td style="width: 89px"> <input type="checkbox" /></td> <td style="width: 210px"> </td> </tr> <tr> <td style="width: 122px; height: 21px"> 2234</td> <td style="width: 89px; height: 21px"> <input type="text" value="aaaaaaa"/></td> <td style="width: 210px; height: 21px"> </td> </tr> <tr> <td style="width: 122px"> 3234</td> <td style="width: 89px"> <input type="checkbox" /></td> <td style="width: 210px"> </td> </tr> </table> </body> </html>
var rows=document.getElementById('tb').rows; for(var i=0;i<rows.length;i++) { var cells=rows[i].cells; for(var j=0;j<cells.length;j++) { alert(cells[j].innerText); } }
<!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").getElementsByTagName('input'); for(var i = 0, len = t.length; i < len; i++ ){ alert( t[i].type ) } } </script> <table id="tb"> <tr> <td style="width: 122px"> 1234</td> <td style="width: 89px"> <input type="checkbox" /></td> <td style="width: 210px"> </td> </tr> <tr> <td style="width: 122px; height: 21px"> 2234</td>