通过更改jQuery中的.val()来更改输入值的事件监听器? [英] Event listener for input's value change through changing with .val() in jQuery?
问题描述
我正在网上搜索如何触发一些jQuery代码,如果表单中输入的值通过使用 .val()
设置其值的脚本进行了更改时,该值会发生变化.可悲的是, on('change')
只听输入的模糊信息.有办法解决这个问题吗?
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()
. on('change')
sadly only listens to the blur of an input. Is there a way to get around this?
如果内部发生某些变化,我想听听包含很多输入内容的表格.
I want to listen to the form which contains many inputs, if something changes inside.
推荐答案
输入值的更改不会自动触发.change()事件.因此,无论您在哪里设置该值,都还必须告诉jQuery触发它.
Changes in the value of input don't automatically fire the .change() event. So, wherever it is that you're setting that value, you also have to tell jQuery to trigger it.
$('selector').val(myValue).trigger('change');
这篇关于通过更改jQuery中的.val()来更改输入值的事件监听器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!