0

我有用于显示项目名称、价格、用于输入金额的输入文本框和用于显示每个项目的价格 * 金额的标签的中继器。我可以用 JavaScript 计算价格 * 金额。这是我用来查找结果的代码(如果需要的话)

function setAmountOther(row) {

    var firstUnderscore = row.indexOf("_");
    var lastUnderscore = row.lastIndexOf("_");

    var totalOther = 0;

    var rowID = row.substring(firstUnderscore, lastUnderscore + 1); // get the control id _ctlXX_ (where XX is row number)

    var rowAmont = Number($('#rptOtherProducts' + rowID + 'txtProductQuantityOther').val()); // get the amount of the product

    var rowPrice = Number($('#rptOtherProducts' + rowID + 'lblProductsPriceOther').text()); // get the price of the product

    totalForRow = rowAmont * rowPrice; // get total for row

    totalOther += totalForRow; // get total for order

    $('#rptOtherProducts' + rowID + 'lblProductTotalOther').html(totalForRow);  // set the total price of the item


} 

问题是如何将每个项目的所有结果添加到显示项目小计的标签中,如果有人更改项目数量,我如何更新它?例如:如果我输入 2 且商品价格为 20,则结果为 40,小计为 40,但如果我输入 1,则结果为 20,但小计仍为 40。

JavaScript 中的任何解决方案、带有 C# 的 asp.net 或任何其他想法都会非常有帮助。(我搜索了但没有发现任何有用的东西,也许我搜索了错误的关键字)

如果您还需要什么,请告诉我。

谢谢

编辑:中继器中的源代码:

<ItemTemplate>
                            <div class="divProductsMain" style="margin: 0 -116px 0 0">
                                <div class="divProdcutTotal">
                                    <label id="lblProductTotalOther" runat="server">
                                        0</label>&nbsp;&#8362;
                                </div>
                                <div class="divProductsQuantity">
                                    <input type="text" id="txtProductQuantityOther" runat="server" class="txtProductQuantity"
                                        maxlength="3" onkeyup="setAmountOther(this.id)" />
                                </div>
                                <div class="divProductsPrice">
                                    <asp:Label ID="lblProductsPriceOther" runat="server"><%#Eval("Price", "{0:0.00}")%></asp:Label>&nbsp;&#8362;
                                </div>
                                <div class="divProductDescription">
                                    <asp:Label ID="lblProductDescriptionOther" runat="server"><%#Eval("Name")%></asp:Label>
                                </div>
                                <div class="divComputerCode">
                                    <asp:Label ID="lblComputerCodeOther" runat="server"><%#Eval("ComputerCode")%></asp:Label>
                                </div>
                            </div>
                        </ItemTemplate>

如果您还需要什么,请告诉我。

4

1 回答 1

0

OnKeyUp在您接受金额和价格的文本框的(事件)上调用计算函数

于 2013-05-02T09:13:19.967 回答