标签:
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title></title> </head> <script src="../mbts/jquery-2.0.3.min.js"></script> <body> <script language="javascript"> function GET_T_TR_TD(node) { //控件 var tdd = node; //对应的td var tdd = node.parentNode; //对应的tr var trr = node.parentNode.parentNode; //对应的table var ta = node.parentNode.parentNode.parentNode; //parentNode是父节点的意思,通过这个可以不停的往上跳 //var t = tr2.previousSbiling; //var t = tr2.nextSbiling; //rows[0].cells[1] 通过这个直接通过节点来访问 //节点的value alert(ta.rows[0].cells[1].childNodes[0].value); alert(ta.rows[0].cells[1].innerHTML); alert(ta.rows[0].cells[1].innerText); } </script> <table id="tb" width="200" border="1" cellpadding="4" cellspacing="0"> <tr> <td height="25">1行</td> <td height="25"><input type="button" name="GET_T_TR_TD" value="获得数据" onclick="GET_T_TR_TD(this)">awdasdawd</td> <td height="25">2行</td> <td height="25">2</td> <td height="25">3</td> <td height="25">4</td> <td height="25">5</td> </tr> <tr> <td height="25">11</td> <td height="25">12</td> <td height="25">13</td> <td height="25">134</td> <td height="25">15</td> <td height="25">16</td> </tr> <tr> <td height="25">1212</td> <td height="25">23</td> <td height="25">34</td> <td height="25">第一行</td> <td height="25">第一行</td> <td height="25">第一行</td> <td height="25">第一行</td> </tr> <tr> <td height="25">第1一行</td> <td height="25">第2一行</td> <td height="25"> <input type="button" name="GET_T_TR_TD" value="获得数据" onclick="GET_T_TR_TD(this)"></td> <td height="25">3</td> <td height="25">第4一行</td> <td height="25">第5一行</td> <td height="25">第6一行</td> </tr> <tr> <td height="25"></td> </tr> </table> </body> <!-- 参考http://www.cnblogs.com/blodfox777/archive/2009/03/16/1413185.html --> </html>
通过这个可以获取html里的节点 再通过节点来获取其他节点的内容
标签:
原文地址:http://www.cnblogs.com/cxl123/p/5847512.html