jQuery: What's the correct code to trigger events in Internet Explorer?
I'm using jQuery 1.2.7 (I cannot upgrade)
In order to trigger events when a dropdown menu selec开发者_运维知识库ted value changes, I've been told to use the following code:
$('#dropdownWidget').bind($.browser.msie ? 'click' : 'change', function(event) {
//myEvent
});
This is a screenshot of the widget:
It works perfectly on all browsers, however in IE, the event is triggered everytime the user clicks on the widget (even before the new value is selected).
Since I'm triggering AJAX calls, I cannot tolerate this. Thanks
I tend to use the click event for all browsers and with IE get the change event to trigger the click event.
$('#dropdownWidget').bind('click', function(event) {
//myEvent
}).bind('change', function(event) {
if ($.browser.msie) {
$(this).click();
}
});
If the change()
event has indeed been fixed as the others suggest, then of course this is redundant. But you may well be stuck using an older jQuery codebase.
so why have you added a check for msie
?
simply try following:
$('#dropdownWidget').bind('change', function(event) {
alert('test'); //myEvent
});
精彩评论