猿问

求指导,这个有啥错误,打印的结果都是undefined?

<!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> new document </title>

  <meta name="generator" content="editplus" />

  <meta name="author" content="" />

  <meta name="keywords" content="" />

  <meta name="description" content="" />

  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

  <style type="text/css">

      body,table,th,td{ font-size: 12px;}

 #tabScore{ border-collapse: collapse;}

 #tabScore th{ padding: 5px;}

 #tabScore td{ padding: 5px;}

  </style>

  <script type="text/javascript">

      function disScore()

 {

 var tab = document.getElementById("tabScore");

 //获取表格中所有行

 var rows = tab.rows;

 

 //获取行中内容

 for (var i = 1;i < rows.length;i++ )

 {

 var name = rows[i].childNodes[0].innerText;

 var java = rows[i].childNodes[1].innerText;

 var html = rows[i].childNodes[2].innerText;

 var sql = rows[i].childNodes[3].innerText;

 var count = rows[i].childNodes[4].innerText;

 alert(name + ":" + java + "," + html + "," + sql + "," + count);

 }

 }

  </script>

 </head>


 <body>

     <input type="button" value="查看表中成绩" onClick="disScore()" />

<hr siize="1">

<table id="tabScore" width="470" border="1" bordercolor="#003399" align="center">

    <tr bgcolor="#0099FF">

    <th>姓名</th><th>Java</th><th>HTML</th><th>SqlServer</th><th>总成绩</th>

</tr>

<tr>

    <td align="center">张三</td>

<td align="center">87</td>

<td align="center">92</td>

<td align="center">79</td>

<td align="center">258</td>

</tr>

<tr>

    <td align="center">李四</td>

<td align="center">70</td>

<td align="center">80</td>

<td align="center">75</td>

<td align="center">225</td>

</tr>

<tr>

    <td align="center">王五</td>

<td align="center">85</td>

<td align="center">75</td>

<td align="center">90</td>

<td align="center">250</td>

</tr>

</table>

 </body>

</html>


夜幕下的雄鹰
浏览 3006回答 3
3回答

badbomb

var name = rows[i].childNodes[0].innerText;  var java = rows[i].childNodes[1].innerText;  var html = rows[i].childNodes[2].innerText;  var sql = rows[i].childNodes[3].innerText;  var count = rows[i].childNodes[4].innerText;改为var name = rows[i].childNodes[1].innerText;  var java = rows[i].childNodes[3].innerText;  var html = rows[i].childNodes[5].innerText;  var sql = rows[i].childNodes[7].innerText;  var count = rows[i].childNodes[9].innerText;

习惯受伤

脚本放到</body>前边,别放到head标签中
随时随地看视频慕课网APP
我要回答