简体   繁体   中英

Triggering a change event for Internet Explorer

I have several select menus that needs that need to have their change events triggered on page load, so that they can automatically use the change behavior from an on('change', ...) handler.

I have it working fine in Firefox, but apparently this doesn't work in Internet Explorer.

Example

var changeEvent  = new Event('change')
input.dispatchEvent(changeEvent);

I have tried finding alternatives in IE, and this is the closest I've come:

ie_event = document.createEvent('change')

ie_event.initEvent('change', function(e) {
    ...
}, false);

document.dispatchEvent(ie_event);

*The above is from codeproject.com , but it doesn't tell me what to put in the ellipses.

Can someone tell me what's wrong, point me in the right direction, or give me an example?

Would this be of any help?

<script>
    $(document).ready(function () {
          $("#select").on("change",function(){
             //do something
          });

          $("#select").trigger("change");
    });
</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM