动态设置值后更改事件未触发 [英] change event not firing after setting value dynamically

查看:67
本文介绍了动态设置值后更改事件未触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过打开弹出窗口动态设置其值,将change事件绑定到textarea(只读)。

I want to bind change event to textarea(read only) whenever its value is set dynamically by opening popup window.

我可以设置值,但是更改事件没有被解雇。

I am able to set the value, but the change event is not getting fired.

我使用下面的代码将更改事件绑定到textarea:

I used below code to bind change event to textarea :

$('textarea[name="Cordinator"]').bind("change", onChangeCordinator);
function onChangeCordinator(){}


推荐答案

如何你在设定值吗?默认情况下,只有在浏览器用户更改了值时才会触发更改事件。

How are you setting the value? By default the change event fires only if the value is changed by the browser user.

如果以编程方式设置值,则需要使用。触发('更改')

If you are setting the value programatically you need to use .trigger('change')

因此,您需要在onclick处理程序中的某处:

So somewhere in your onclick handler you need:

$('textarea[name="Cordinator"]').trigger('change');

这篇关于动态设置值后更改事件未触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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