JavaScript统计HTML表格中的值:
<script language="JavaScript">
function test()
{
var tab=document.getElementById("myTable");
var count=0;
for(i=0;i<tab.rows.length;i++)
{
for(j=0;j<tab.rows[i].cells.length;j++)
{
count+=parseInt(tab.rows[i].cells[j].innerText);
}
}
alert("和为:"+count);
}
</script>
JavaScript统计HTML表格中的值:
<html>
<head>
<title>JavaScript统计HTML表格中的值</title>
</head>
<script language="JavaScript">
function test()
{
var tab=document.getElementById("myTable");
var count=0;
for(i=0;i<tab.rows.length;i++)
{
for(j=0;j<tab.rows[i].cells.length;j++)
{
count+=parseInt(tab.rows[i].cells[j].innerText);
}
}
alert("和为:"+count);
}
</script>
<body onClick="test()">
<table id="myTable">
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td>4</td>
<td>5</td>
<td>6</td>
</tr>
<tr>
<td>7</td>
<td>8</td>
<td>9</td>
</tr>
<tr>
<td>10</td>
<td>11</td>
<td>12</td>
</tr>
</table>
</body>
</html>