通过 document.getElementById(...).value 设置值后的 jQuery 更改事件
我正在尝试处理更改事件,但似乎不起作用。我想在通过 document.getElementById('id_of_input').value 设置值后使用 jQuery 处理该事件。这是代码: http://jsbin.com/axagej (编辑请参阅:http://jsbin.com/axagej/edit) - 我想查看警报。
I'm trying to handle change event, but it seems it doesn't work. I would like to handle the event using jQuery after setting value via document.getElementById('id_of_input').value
. Here is the code: http://jsbin.com/axagej (to edit see: http://jsbin.com/axagej/edit) - I would like to see an alert.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
更改事件对我来说效果很好。这只是当你失去焦点时的表现。如果您在写作时更喜欢提醒,您应该对 jQuery 键盘事件感兴趣 (http:// /api.jquery.com/category/events/keyboard-events/)。
@tchaOo
The change event is working fine for me. It's just acting when you lost focus. If you prefer alert while writing, you should be interested by the jQuery keyboard events (http://api.jquery.com/category/events/keyboard-events/).
@tchaOo
如果您以编程方式设置值,则需要使用 change 或 触发:
或
If you're setting the value programatically you need to fire the event yourself using change or trigger:
or
当您以编程方式更改字段的值时,您不会收到更改事件。您需要显式调用更改处理程序。查看更新后的 jsbin:http://jsbin.com/axagej/2/edit
When you're programmatically changing the value of a field, you won't get a change event. You'll need to explicitly invoke the change handler. See the updated jsbin: http://jsbin.com/axagej/2/edit