我在我的html文件中创建了这段代码:
<table>
<tr>
<td><span id="x1">6</span></td>
<td>
<select id="y1">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
</td>
<td><span id="z1">X</span></td>
</tr>
<tr>
<td><span id="x2">6</span></td>
<td>
<select id="y2">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
</td>
<td><span id="z2">X</span></td>
</tr>
</table>
<div id="total">TOTAL</div>
我在.js文件中创建了这段代码:
$(document).ready(function () {
$("select").change(function () {
var m = 0;
for (var i = 1; i < 3; i++) {
var x = "#x" + i;
var y = "#y" + i;
var z = "#z" + i;
var first = $(x).text();
var seconde = $(y).val();
var third = first * seconde;
$(z).html(third);
var m = m + third;
}
$("#total").text(m);
});
});
当我运行html文件并运行代码时,在#total ID中显示NaN
。但其他部分运作良好。这段代码怎么了?