如何调用javascript的onload?[英] how to call javascript onload?

问题描述

我有一个 java 脚本函数,它通过将价格 * 乘以质量来帮助计算总成本

<脚本 type="text/javascript">$("[id*=txtQuality]").live("更改", 函数 () {if (isNaN(parseInt($(this).val()))) {$(this).val('0');} else {$(this).val(parseInt($(this).val()).toString());}});$("[id*=txtQuality]").live("keyup", 函数 () {if (!jQuery.trim($(this).val()) == '') {if (!isNaN(parseFloat($(this).val()))) {var row = $(this).closest("table");$("[id*=lblTotal]", row).html(parseFloat($("[id*=price]", 行).html()) * parseFloat($(this).val()));}} else {$(this).val('');}});</脚本>
然而,当加载 default.aspx 时,txtQuality 将从数据库表中检索一个计数值,但是如果只更改表值,javascript 将如何工作,**但除此之外,我还希望得到一个结果,即在加载 default.aspx 时,"lblTotal"有一个由 javascript 使用计数值计算的金额 * price**

受保护 Sub GridView1_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) 句柄 GridView1.RowDataBoundIf e.Row.RowType = DataControlRowType.DataRow 然后Dim txt As TextBox = DirectCast(e.Row.FindControl("txtQuality"), TextBox)Dim 适配器 As  SqlDataAdapterDim ds As 新建数据集'Dim sql As StringDim connectionString = ConfigurationManager.ConnectionStrings("ProjData").ConnectionStringDim myConn As New SqlConnection(connectionString)Dim cmd = "Select * From Product Where customerID='" &会话("customerID") &"' "' Dim myCmd As New SqlCommand(cmd, myConn)试试myConn.Open()Dim myCmd As New SqlCommand(cmd,我的康)适配器.SelectCommand = myCmdadapter.Fill(ds, "Product")适配器.Dispose()myCmd.Dispose()txt.Text = ds.Tables(0).Rows.CountCatch ex As 例外MsgBox("无法打开连接!")结束 试试结束 如果结束 

<ItemTemplate><table style="width: 79%; height: 31px;"><tr><td class="style1"><asp:Label ID="Label7" runat="服务器" 文本="价格 $"></asp:Label></td><td ><asp:Label ID="price" runat="服务器" 文本='<%# Bind("costPerTable") %>' ></asp:Label></td></tr><tr><td class="style1"><asp:Label ID="Label2" runat="服务器" 文本="数量"></asp:Label></td><td><asp:TextBox ID="txtQuantity" runat="服务器"></asp:文本框></td></tr><tr><td class="style1"><asp:Label ID="Label8" runat="服务器" 文本="总费用:"></asp:Label></td><td>$<asp:Label ID="lblTotal" runat="服务器" ></asp:Label></td></tr></table></ItemTemplate></asp:TemplateField>

推荐答案

("[id*=txtQuality]").live("change", 函数 () {if (isNaN(parseInt(blockquote>
(this).val()))) {

(this).val('0');} else {

本文地址:https://www.itbaoku.cn/post/1395209.html