Why does dynamically changing a checkbox not trigger a form change event?

前端 未结 2 577
刺人心
刺人心 2020-12-09 15:35

I wrote this snippet of javascript/jQuery to change a check box. http://jsfiddle.net/johnhoffman/crF93/

Javascript

$(function() {
    $(\"a\").click(         


        
2条回答
  •  既然无缘
    2020-12-09 16:21

    You need to trigger the change event, .trigger('change'), so that event knows that a change took place.

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

    Description: Bind an event handler to the "change" JavaScript event, or trigger that event on an element.

    This method is a shortcut for .on( "change", handler ) in the first two variations, and .trigger( "change" ) in the third.

    The change event is sent to an element when its value changes. This event is limited to elements,