我对Javascript非常陌生,我在gridview中更新文本框时遇到问题。
这是我目前的尝试
function startCalc() {
var grid = document.getElementById("GridView1");
for (var i = 0; i < grid.rows.length - 1; i++) {
var rate = $("Span[id*=Rate]");
var qty = $("input[id*=TextAmount]");
var ra = parseFloat(rate[i].textContent);
$("input[id*=TextVat]") = qty[i].value * parseFloat(rate[i].textContent);
}
}
但是我一直收到一条错误,指出无法分配给函数结果。
任何帮助将不胜感激
下面是我的gridview中的一段代码,其中我想要将TextBox ID =“TextAmount”乘以Label ID =“Rate”并将结果放入TextBox ID =“TextVat”
<asp:GridView ID="GridView1" runat="server" AllowSorting="True" DataSourceID="SqlDataSource1" Height="138px" AutoGenerateColumns="False" HorizontalAlign="Center" BackColor="White" BorderColor="#CCCCCC" BorderStyle="Groove" BorderWidth="1px" CellPadding="4" ForeColor="Black" GridLines="Horizontal">
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True" SortExpression="ID" />
<asp:BoundField DataField="item" HeaderText="item" SortExpression="item" />
<asp:TemplateField HeaderText="Vat" SortExpression="Vat">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Vat") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Rate" runat="server" Text='<%# Bind("Vat") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Quantity">
<ItemTemplate><asp:TextBox ID="TextQuantity" runat="server" class="calculate" onchange="calculate()" Text="0" ></asp:TextBox></ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Amount">
<ItemTemplate><asp:TextBox ID="TextAmount" runat="server" class="calc" onchange="calc()" Text="0" ></asp:TextBox></ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Vat Amount">
<ItemTemplate><asp:TextBox ID="TextVat" runat="server" ></asp:TextBox></ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#CCCC99" ForeColor="Black" />
<HeaderStyle ForeColor="White" BackColor="#333333" Font-Bold="True" />
<PagerStyle BackColor="White" ForeColor="Black" HorizontalAlign="Right" />
<SelectedRowStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F7F7F7" />
<SortedAscendingHeaderStyle BackColor="#4B4B4B" />
<SortedDescendingCellStyle BackColor="#E5E5E5" />
<SortedDescendingHeaderStyle BackColor="#242121" />
</asp:GridView>
由于
答案 0 :(得分:0)
要使用jquery为输入元素赋值,您应该使用val()方法:
$('input').val(your value);
因此,为了解决您的问题代码应该是:
var vatValue = qty[i].value * parseFloat(rate[i].textContent);
$('input[id*="TextVat"]').val(vatValue);