我正在编写一个脚本,该脚本本质上应该是每次用户在选定的文本框中输入值时更新表单的总成本。我的问题是我不确定为什么即使在通话后它也没有更新。我知道我在某个地方犯了一个错误,我只是不确定在哪里。
$(document).ready(function () {
var total = document.getElementById(txtTotalCost);
ComputeCosts();
total.blur(function () {
ComputeCosts();
});
});
function ComputeCosts()
{
var amount1 = document.getElementById(txtPAmount1);
var amount2 = document.getElementById(txtPAmount2);
var amount3 = document.getElementById(txtPAmount3);
var amount4 = document.getElementById(txtPAmount4);
var amount5 = document.getElementById(txtPAmount5);
var totalBox = document.getElementById("txtTotalCost");
var totalGift = (txtPAmount1.val() +txtPAmount2.val() + txtPAmount3.val()+txtPAmount4.val()+txtPAmount5.val()).toFixed(2);
totalBox.val(totalGift);
}
这是它的html方面:
<asp:TextBox runat="server" ID="txtPAmount1" CssClass="narrow" onClick="ComputeCosts();" text="0.00" />
<asp:TextBox runat="server" ID="txtPAmount2" CssClass="narrow" onClick="ComputeCosts();" text="0.00" />
<asp:TextBox runat="server" ID="txtPAmount3" CssClass="narrow" onClick="ComputeCosts();" text="0.00" />
<asp:TextBox runat="server" ID="txtPAmount4" CssClass="narrow" onClick="ComputeCosts();" text="0.00" />
<asp:TextBox runat="server" ID="txtTotalCost" CssClass="narrow" onClick="ComputeCosts();" text="0.00" />