简体   繁体   English

通过在 jQuery 中更改 .val() 来更改输入值的事件侦听器?

[英]Event listener for input's value change through changing with .val() in jQuery?

I was searching the web for how to fire of some jQuery code if the value of an input inside a form changes if it gets changed through a script that sets it's value with .val() .我在网上搜索如何触发一些 jQuery 代码,如果表单内的输入值发生变化,如果它通过一个设置它的值的脚本更改.val() on('change') sadly only listens to the blur of an input. on('change')遗憾的是只听输入的模糊。 Is there a way to get around this?有没有办法解决这个问题?

I want to listen to the form which contains many inputs, if something changes inside.如果内部发生变化,我想听包含许多输入的表单。

Changes in the value of input don't automatically fire the .change() event.输入值的变化不会自动触发 .change() 事件。 So, wherever it is that you're setting that value, you also have to tell jQuery to trigger it.因此,无论您在何处设置该值,都必须告诉 jQuery 触发它。

 $('selector').val(myValue).trigger('change');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM