简体   繁体   中英

Why doesn't jQuery fire the 'input' event on $.val('') input set

Why doesn't the input event get fired when I changed a text input's value via jQuery.val('')?

http://jsfiddle.net/EC85C/2/

https://developer.mozilla.org/en-US/docs/Web/Reference/Events/input

My guess is you're trying to get AngularJS to see your changes (via bindings) when you change the value of your input (through jQuery's val method)?

I've thrown together this fiddle to illustrate how to get this to work: http://jsfiddle.net/6JTDf/1/

Instead of calling trigger (which creates a jQuery 'event'), you can create a synthetic UIEvent (in our case, 'input'), and then dispatch that on the element. This synthetic event will trigger both the event listener (hello alert!), and the angular binding.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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