日期:2014-05-16  浏览次数:20402 次

获取指定tr内的div的值
<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>
如上,根据node-id 取得指定div内的值,1和2 ;解决问题会有加分,谢谢
问题补充:
html代码不能改动

------解决方案--------------------
HTML code
<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>

------解决方案--------------------
HTML code
<!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>