0

ASP.Net ページ内に HTML テーブルがあり、ASP.Net テキスト ボックスを使用して、テーブル内でのみすべてのテキスト ボックスを合計できる必要があります。

ページ上のすべてのテキスト ボックスを正常に動作させるスクリプトがありますが、それを絞り込む方法が見つからないようです。

このサイトで、テーブルを識別してからすべてのセルを通過するスクリプトを見つけましたが、実装しようとすると「セル」が認識されません。

何か案は?

4

1 に答える 1

0

This will do the trick

enter image description here

<script type="text/javascript" src="Scripts/jquery-1.7.2.min.js"></script>
<script type="text/javascript">
    $(function () {
        $("#calculate").click(function () {
            var res = 0;
            $("#table input:text").each(function (i, e) {
                if ($(e).val() !== "") {
                    res += parseInt($(e).val());
                }
            });
            alert(res);
        });
    });
</script>


    <table id="table" border="0" cellpadding="0" cellspacing="0">
        <tr>
            <td>
                <asp:TextBox runat="server" ID="txt1" />
            </td>
            <td>
                <asp:TextBox runat="server" ID="txt2" />
            </td>
        </tr>
        <tr>
            <td>
                <asp:TextBox runat="server" ID="txt3" />
            </td>
            <td>
                <asp:TextBox runat="server" ID="txt4" />
            </td>            
        </tr>
    </table>
    <input type="button" id="calculate" value="calculate" />
    <asp:TextBox runat="server" ID="TextBox1" Text="0" />
    <asp:TextBox runat="server" ID="TextBox2" Text="0" />
    <asp:TextBox runat="server" ID="TextBox3" Text="0" />

Only the text boxes inside the table are processed

于 2012-08-10T21:20:15.500 に答える