如何调用javascript onload? [英] how to call javascript onload?
本文介绍了如何调用javascript onload?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个Java脚本功能,可以通过按价格*质量来帮助计算总成本
I have a java script function which help to calculate the total cost by taking the price * by the quality
<script type="text/javascript">
$("[id*=txtQuality]").live("change", function () {
if (isNaN(parseInt($(this).val()))) {
$(this).val('0');
} else {
$(this).val(parseInt($(this).val()).toString());
}
});
$("[id*=txtQuality]").live("keyup", function () {
if (!jQuery.trim($(this).val()) == '') {
if (!isNaN(parseFloat($(this).val()))) {
var row = $(this).closest("table");
$("[id*=lblTotal]", row).html(parseFloat($("[id*=price]", row).html()) * parseFloat($(this).val()));
}
} else {
$(this).val('');
}
});
</script>
,但是在加载default.aspx时,txtQuality将从数据库表中检索计数值,但是如果仅更改表值,javascript将如何工作, **但是除此之外,我还希望得到一个结果,当加载default.aspx时,"lblTotal"具有使用计数值*价格**由javascript计算的金额**
however when load the default.aspx, the txtQuality will retrieve a count value from the database table , but how the javascript will work if only the table value is change, **but beside that i also want to have a result that when default.aspx is load, the "lblTotal" have a amount calculate by the javascript by using the count value * price**
Protected Sub GridView1_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
Dim txt As TextBox = DirectCast(e.Row.FindControl("txtQuality"), TextBox)
Dim adapter As New SqlDataAdapter
Dim ds As New DataSet
'Dim sql As String
Dim connectionString = ConfigurationManager.ConnectionStrings("ProjData").ConnectionString
Dim myConn As New SqlConnection(connectionString)
Dim cmd = "Select * From Product Where customerID='" & Session("customerID") & "' "
' Dim myCmd As New SqlCommand(cmd, myConn)
Try
myConn.Open()
Dim myCmd As New SqlCommand(cmd, myConn)
adapter.SelectCommand = myCmd
adapter.Fill(ds, "Product")
adapter.Dispose()
myCmd.Dispose()
txt.Text = ds.Tables(0).Rows.Count
Catch ex As Exception
MsgBox("Can not open connection ! ")
End Try
End If
End Sub
<ItemTemplate>
<table style="width: 79%; height: 31px;">
<tr>
<td class="style1">
<asp:Label ID="Label7" runat="server" Text="price $"></asp:Label>
</td>
<td >
<asp:Label ID="price" runat="server" Text='<%# Bind("costPerTable") %>' ></asp:Label>
</td>
</tr>
<tr>
<td class="style1">
<asp:Label ID="Label2" runat="server" Text="Quantity"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtQuantity" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style1">
<asp:Label ID="Label8" runat="server" Text="Total Cost:"></asp:Label>
</td>
<td>
$<asp:Label ID="lblTotal" runat="server" ></asp:Label>
</td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateField>
推荐答案
(" ).live( 更改",如果( isNaN ( parseInt (
("[id*=txtQuality]").live("change", function () { if (isNaN(parseInt(
( this ).val()))){
(this).val()))) {
(此).val(' 0'); } 其他 {
(this).val('0'); } else {
这篇关于如何调用javascript onload?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文