我有 7 个文本框。我想添加 7 的值并将总数插入另一个文本框。我如何在没有回发的情况下实现这一目标。我也尝试过更新面板,但它不起作用。我的代码如下。在这方面的任何建议都会非常明显
If Page.IsPostBack Then
Dim A1 As Double
A1 = A_SAtxt.Text
Dim A2 As Double
A2 = A_SStxt.Text
Dim A3 As Double
A3 = A_RAtxt.Text
Dim A4 As Double
A4 = A_CAtxt.Text
Dim A5 As Double
A5 = A_OItxt.Text
Dim A6 As Double
A6 = A_ICtxt.Text
Dim A7 As Double
A7 = A_Otxt.Text
Dim ATotal = A1 + A2 + A3 + A4 + A5 + A6 + A7
万一
我使用 VB 在 asp.net 中工作。asp.net中的文本框代码如下
<table width="100%">
<tr>
<td align="left" style="border:1px solid #cccccc; text- align: right; background-color: #F0F0F0;"
valign="top" class="style7" width = "400px">
<asp:Label ID="Label154" runat="server" Text="Savings account $"></asp:Label>
</td>
<td align="center" class="style7"
style="border:1px solid #cccccc; text-align: left; background-color: #F0F0F0;"
valign="top">
<asp:TextBox ID="A_SAtxt" runat="server" CssClass="DrpItems10"
style="text-align: left" MaxLength="25"></asp:TextBox>
</td>
</tr>
<tr>
<td align="center" class="style7"
style="border:1px solid #cccccc; text-align: right; background-color: #F0F0F0;"
valign="top">
<asp:Label ID="Label155" runat="server" Text="Stock and securities $"></asp:Label>
</td>
<td align="center" class="style7"
style="border:1px solid #cccccc; text-align: left; background-color: #F0F0F0;"
valign="top">
<asp:TextBox ID="A_SStxt" runat="server" CssClass="DrpItems10"
style="text-align: left" MaxLength="25"></asp:TextBox>
</td>
</tr>
<tr>
<td align="center" class="style7"
style="border:1px solid #cccccc; text-align: right; background-color: #F0F0F0;"
valign="top">
<asp:Label ID="Label156" runat="server" Text="Retirement accounts $"></asp:Label>
</td>
<td align="center" class="style7"
style="border:1px solid #cccccc; text-align: left; background-color: #F0F0F0;"
valign="top">
<asp:TextBox ID="A_RAtxt" runat="server" CssClass="DrpItems10"
style="text-align: left" MaxLength="25"></asp:TextBox>
</td>
</tr>
<tr>
<td align="center" class="style7"
style="border:1px solid #cccccc; text-align: right; background-color: #F0F0F0;"
valign="top">
<asp:Label ID="Label157" runat="server" Text="Checking account $"></asp:Label>
</td>
<td align="center" class="style7"
style="border:1px solid #cccccc; text-align: left; background-color: #F0F0F0;"
valign="top">
<asp:TextBox ID="A_CAtxt" runat="server" CssClass="DrpItems10"
style="text-align: left" MaxLength="25"></asp:TextBox>
</td>
</tr>
<tr>
<td align="center" class="style7"
style="border:1px solid #cccccc; text-align: right; background-color: #F0F0F0;"
valign="top">
<asp:Label ID="Label158" runat="server" Text="Other investments $"></asp:Label>
</td>
<td align="center" class="style7"
style="border:1px solid #cccccc; text-align: left; background-color: #F0F0F0;"
valign="top">
<asp:TextBox ID="A_OItxt" runat="server" CssClass="DrpItems10"
style="text-align: left" MaxLength="25"></asp:TextBox>
</td>
</tr>
<tr>
<td align="center" class="style7"
style="border:1px solid #cccccc; text-align: right; background-color: #F0F0F0;"
valign="top">
<asp:Label ID="Label159" runat="server" Text="Insurace cash-in-value $"></asp:Label>
</td>
<td align="center" class="style7"
style="border:1px solid #cccccc; text-align: left; background-color: #F0F0F0;"
valign="top">
<asp:TextBox ID="A_ICtxt" runat="server" CssClass="DrpItems10"
style="text-align: left" MaxLength="25"></asp:TextBox>
</td>
</tr>
<tr>
<td align="center" class="style7"
style="border:1px solid #cccccc; text-align: right; background-color: #F0F0F0;"
valign="top">
<asp:Label ID="Label160" runat="server" Text="Other $"></asp:Label>
</td>
<td align="center" class="style7"
style="border:1px solid #cccccc; text-align: left; background-color: #F0F0F0;"
valign="top">
<asp:TextBox ID="A_Otxt" runat="server" CssClass="DrpItems10"
style="text-align: left" MaxLength="30"></asp:TextBox>
<asp:Label ID="Label188" runat="server" Text="specify:" Font-Italic="true"></asp:Label>
<asp:TextBox ID="A_OStxt" runat="server" CssClass="DrpItems10"
style="text-align: left" Width="250px" MaxLength="100"></asp:TextBox>
</td>
</tr>
<tr>
<td align="center" class="style7"
style="border:1px solid #cccccc; text-align: right; background-color: #F0F0F0;"
valign="top">
<asp:Label ID="Label161" runat="server" Text="Total assets $"></asp:Label>
</td>
<td align="center" class="style7"
style="border:1px solid #cccccc; text-align: left; background-color: #F0F0F0;"
valign="top">
<asp:TextBox ID="A_TAtxt" runat="server" CssClass="DrpItems10"
style="text-align: left" MaxLength="25"></asp:TextBox>
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
我什至尝试过这样做,但它似乎不起作用
Dim sb As New System.Text.StringBuilder()
sb.Append("<script type = 'text/javascript'>")
sb.Append(" $(document).ready(function() {")
sb.Append(" var numberInput = $('#A_SAtxt, #A_SStxt, #A_RAtxt, #A_CAtxt,
#A_OItxt, #A_ICtxt, #A_Otxt');")
sb.Append(" numberInput.on('change', function() {")
sb.Append(" var total = 0;")
sb.Append("else{")
sb.Append(" numberInput.each(function() {")
sb.Append(" if ($(this).val() !== '') {")
sb.Append(" total += parseFloat($(this).val());")
sb.Append(" }")
sb.Append(" });")
sb.Append(" $('#A_TAtxt').val(total);")
sb.Append(" });")
sb.Append(" });")
sb.Append("}};</script>")
ClientScript.RegisterClientScriptBlock(Me.GetType(), "function", sb.ToString())