当
通常,当用户选择 的值时,该事件不会被触发。
我知道我可以这样做: $('select').val('something').trigger('change');
但这不是我想要解决的问题...
有没有办法让更改事件正常工作,而无需手动触发它?
我整理了一个快速的 JsFiddle 来更好地解释问题,请查看:
干杯
Normally, when a user selects an item in a <select>
, the 'change' event gets fired.
However, when you change the value of the same <select>
with $('select').val('something')
, the event doesn't get fired.
I know I could do:$('select').val('something').trigger('change');
but that's not the problem I'm trying to solve...
Is there a way to get the change event working, without manually triggering it?
I put together a quick JsFiddle to better explain the problem, check it out:
Cheers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是不可能的,除非您手动触发更改功能。如果您不喜欢多次键入该代码,请扩展 jQuery 对象。 小提琴:http://jsfiddle.net/W723K/2/
It's not possible, unless you manually trigger the change function. If you don't like typing that code several times, extend the jQuery object. Fiddle: http://jsfiddle.net/W723K/2/