开发者

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/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜