这段代码给我看错了什么?

时间:2017-02-11 07:10:24

标签: jquery

我在我的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。但其他部分运作良好。这段代码怎么了?

0 个答案:

没有答案