Why does the jquery change event not trigger when I set the value of a select using val()?

后端 未结 9 950
猫巷女王i
猫巷女王i 2020-11-22 09:34

The logic in the change() event handler is not being run when the value is set by val(), but it does run when user selects a value with their mouse

9条回答
  •  北恋
    北恋 (楼主)
    2020-11-22 10:18

    As far as I can read in API's. The event is only fired when the user clicks on an option.

    http://api.jquery.com/change/

    For select boxes, checkboxes, and radio buttons, the event is fired immediately when the user makes a selection with the mouse, but for the other element types the event is deferred until the element loses focus.

提交回复
热议问题