How does $(document).ready() work in IE 8?

后端 未结 6 2063
暗喜
暗喜 2020-12-11 03:16

I\'ve recently installed IE 8 and can\'t seem to get the jquery $(document).ready event to fire. Are there any special considerations that I\'m missing? Litterally, this i

6条回答
  •  一整个雨季
    2020-12-11 03:35

    $(document).ready()
    

    Not work in IE8 I find a code sample from this link https://plainjs.com/javascript/events/running-code-when-the-document-is-ready-15/ It is working with Jquery 1.10.2

    	function run() {
        // do something
        alert('working');
    }
    
    // in case the document is already rendered
    if (document.readyState!='loading') run();
    // modern browsers
    else if (document.addEventListener) document.addEventListener('DOMContentLoaded', run);
    // IE <= 8
    else document.attachEvent('onreadystatechange', function(){
        if (document.readyState=='complete') run();
    });

提交回复
热议问题