使用jquery的文本框onchange事件导致JScript运行时错误:'Deductions'未定义 [英] textbox onchange event using jquery causes JScript runtime error: 'Deductions' is undefined

查看:129
本文介绍了使用jquery的文本框onchange事件导致JScript运行时错误:'Deductions'未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个有关为文本框onchange事件调用jQuery的查询.

I have a query regarding calling jQuery for textbox onchange event.

在我的编码中,我将onchange事件称为

in my coding am calling onchange event as

<asp:TextBox ID="txtTotalDeductions"  Text="0" runat="server" 
                                                        ClientIDMode="Static"     onChange="Deductions();" ></asp:TextBox>

我有两个div部分作为

and I have two div sections as

<div id="Total">1000</div>

<div id="NetTotal">0</div>

我需要通过减去总计-txtTotalDeductions"来计算"NetTotal".

I need to calculate the "NetTotal" by subtracting the Total - txtTotalDeductions.

我的推论jQuery是

and my jQuery for Deductions is

//计算扣除额.

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运行时错误:'推论'未定义",错误位于此处"

and when I run the application the error shows like "Microsoft JScript runtime error: 'Deductions' is undefined", and the error lies here ""

有人可以帮助我吗?....提前谢谢

can anyone help me out pls.....thanks in advance

推荐答案

删除OnChange处理程序

remove the OnChange handler

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事件处理程序

also wrap the code inside the ready handler and attach a change event handler

$(document).ready(function(){
 //attach with the id od deductions
$("#txtTotalDeductions").bind("change",Deductions);

});

这篇关于使用jquery的文本框onchange事件导致JScript运行时错误:'Deductions'未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆