When Form UI is changed programmatically, event handler won't fire for sure?
I realized that on a webpage, when a form's UI (checkbox, dropdown list, etc) is changed programmatically, the event handler (onchanged) is not fired? Is this a standard rule --开发者_如何学C that when a control is changed programmatically, the event handler will never get triggered? Is there any exception?
That is correct, unless as Pointy "pointed" out, you are also firing the event. In jQuery this is as easy as adding a call to .change()
in your code that is changing the form.
Ex. -
Html:
<form id="aForm">
<input></input><br />
<input></input><br />
<input type="checkbox"></input><br />
<input type="checkbox"></input><br />
</form>
jQuery:
$('#aForm').change(function() {
alert('Your form hath changed!');
})
$('#aForm').hide(function(){
$(this).change();
});
jsFiddle working example - http://jsfiddle.net/qGLc2/
精彩评论