开发者

order of events when a DOM element event is triggered

开发者 https://www.devze.com 2023-03-05 12:54 出处:网络
I have a Javascript function bound to the click event of an INPUT element (either checkbox or radio). That function examines the \'checked\' property of the DOM element and takes action depending upon

I have a Javascript function bound to the click event of an INPUT element (either checkbox or radio). That function examines the 'checked' property of the DOM element and takes action depending upon whether it is set or not.

If the user clicks on the element as represented in the GUI, the state of the checked property reflects the appearance in the GUI (that is, if the user's click activated the element, the checked property is true).

However, if I trigger the click event (using jQuery), then, when the bound-to-the-click function is invoked, examining the state of the checked property does NOT show the new state. However, the GUI d开发者_如何学Gooes get updated to present proper representation of the actual state.

Is there a defined order to when these activities are performed? It seems odd to me that the event listener would be invoked before the checked property is set.


Interesting. The .click() called through jQuery has a different behaviour than calling .click() direct on the element. See here :

http://jsfiddle.net/g4aVm/6/

I would take this to indicate that jQuery is doing something non-standard/buggy here.

(I'm slight old fashioned and don't trust jQuery with simple DOM stuff. There's not much to gain by using a library to replicate what already exists, but that's a different discussion.)

0

精彩评论

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