我有一个 asp:repeater
,它有两个文本框。单击按钮时(该按钮位于中继器外部),textbox1 中的所有值都应添加到 textbox2 中,如下所示
txtprice2.val = txtprice1.val + txtprice2.val;
中继器标记为
<asp:Repeater ID="Repeater1" runat="server">
<HeaderTemplate>
<table id="tbl_priceCal" border="0" cellpadding="5" cellspacing="0">
<tr>
<th>
ItemNo
</th>
<th>
Name
</th>
<th>
Price1
</th>
<th>
Price2
</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<%#Eval("ItemNo")%>
</td>
<td class="Name">
<%#Eval("Name")%>
</td>
<td>
<asp:TextBox ID="txtprice1" runat="server" Text='<%#Eval("txtprice1")%>'></asp:TextBox>
</td>
<td>
<asp:TextBox ID="txtprice2" runat="server" Text='<%#Eval("txtprice2")%>'></asp:TextBox>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
如何使用 jQuery 做到这一点?
最佳答案
最简单的方法是将两个CSSClassprice1和price2分配给txtPrice1和txtPrice2。
<asp:TextBox ID="txtprice1" runat="server"
Text='<%#Eval("txtprice1")%>'
CssClass="price1">
</asp:TextBox>
<asp:TextBox ID="txtprice2" runat="server"
Text='<%#Eval("txtprice2")%>'
CssClass="price2">
</asp:TextBox>
然后点击按钮写下这个。
$("#some_button").on("click", function () {
e.preventDefault();
$(".price1").each(function () {
var price1TextBox = $(this);
var price2TextBox = price1TextBox.closest("tr").find(".price2");
var price2NewValue = +price1TextBox.val() + +price2TextBox.val();
price2TextBox.val(price2NewValue);
});
});
关于jquery - 将值从转发器文本框转移到另一个文本框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30047398/