我有一个关于为textBox onchange事件调用jQuery的查询.
在我的编码我呼吁onchange事件为
<asp:TextBox ID="txtTotalDeductions" Text="0" runat="server" ClientIDMode="Static" onChange="Deductions();" ></asp:TextBox>
我有两个div部分
<div id="Total">1000</div>
和
<div id="NetTotal">0</div>
我需要通过减去Total – txtTotalDeductions来计算“NetTotal”.
而我的jQuery for Deductions是
//计算扣减额.
function Deductions() { var result = new Object(); result.total = $("#Total").html(); result.totalDeductions = $("#txtTotalDeductions").val(); result.netTotal = result.total - result.totalDeductions; $('#NetTotal').html(result.netTotal); }
当我运行应用程序时,错误显示为“Microsoft JScript运行时错误:’扣除’未定义”,错误在于“”
任何人都可以帮助我…请提前谢谢
解决方法
删除OnChange处理程序
function Deductions() { var result = new Object(); result.total = $("#Total").html(); result.totalDeductions = $("#txtTotalDeductions").val(); result.netTotal = result.total - result.totalDeductions; $('#NetTotal').html(result.netTotal); }
还将代码包装在ready处理程序中并附加change事件处理程序
$(document).ready(function(){ //attach with the id od deductions $("#txtTotalDeductions").bind("change",Deductions); });