日期:2014-05-16 浏览次数:20402 次
<table> <tbody> <tr class="datagrid-row" node-id="000000010" style="height: 25px; "> <td class="datagrid-td-rownumber"><div class="datagrid-cell-rownumber">1</div></td> </tr> <tr class="datagrid-row" node-id="000000012" style="height: 25px; "> <td class="datagrid-td-rownumber"><div class="datagrid-cell-rownumber">2</div></td> </tr> </tbody> </table> <script type="text/javascript"> function getRowNumber(nodeID) { var obj = document.getElementsByTagName('table')[0].getElementsByTagName('tbody')[0].getElementsByTagName('tr'); for (var i = 0; i < obj.length; i ++) if (obj[i].getAttribute('node-id') == nodeID) return obj[i].getElementsByTagName('div')[0].innerHTML; } alert(getRowNumber('000000010')); //1 alert(getRowNumber('000000012')); //2 </script>
------解决方案--------------------
<!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> <meta http-equiv="content-type" content="text/html; charset=utf-8"/> <title></title> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> <script type="text/javascript"> $(function () { alert($("tr[node-id='000000010']>td>div").html()); alert($("tr[node-id='000000012']>td>div").html()); }) </script> </head> <body > <table> <tbody> <tr class="datagrid-row" node-id="000000010" style="height: 25px; "> <td class="datagrid-td-rownumber"> <div class="datagrid-cell-rownumber">1</div> </td> </tr> <tr class="datagrid-row" node-id="000000012" style="height: 25px; "> <td class="datagrid-td-rownumber"> <div class="datagrid-cell-rownumber">2</div> </td> </tr> </tbody> </table> </body> </html>