以编程方式更改内容时检测文本框更改 [英] detecting textbox change when changing the content programmatically

查看:81
本文介绍了以编程方式更改内容时检测文本框更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个链接到jQuery事件处理程序的文本框,如下所示:

I have a textbox that's linked to a jquery event handler like this:

$('#SomeDiv').on({

   mouseenter: ....
   mouseleave: ....
   blur: ....
   keyup: function() { HandlerForKeyUp($(this)); } ,
   change: function() { HandlerForKeyUp($(this)); } 

}, '.MyTextBoxes');

基本上,HandlerForKeyUp是一个显示文本框中字母数量计数器的功能.用户输入时可以正常工作.

Basically, HandlerForKeyUp is a function that shows a counter of the number of letters in the textbox. It works fine when the user is typing.

但是,如果我这样写:

$('#SomeTextBox').val(SomeValue);

HandlerForKeyUp函数不会触发,甚至以为我在.on处理程序中映射了change事件,并且SomeTextBox是类MyTextBoxes,并且对所有其他事件做出反应.基本上,如果用户键入计数器就可以了,但是如果我在运行时设置了文本框的值,则计数器功能不会触发.

the HandlerForKeyUp function doesn't trigger, even thought I have the change event mapped out in the .on handler and SomeTextBox is of class MyTextBoxes and reacts to all other events. Basically, if the user types the counter works but if I set the value of the textbox at runtime the counter function doesn't trigger.

关于如何更改此设置的任何想法吗?

Any idea on how I could change this?

感谢您的建议.

推荐答案

您需要手动触发更改事件.

You need to fire the change event manually.

$('#SomeTextBox').val(SomeValue).change();

这篇关于以编程方式更改内容时检测文本框更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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