简体   繁体   English

javascript无法在IE8 / 9中运行,但在查看控制台时可以运行

[英]javascript doesn't run in IE8/9 but does when viewing console

I have a script that works fine in everything but IE8/9. 我有一个脚本,除了IE8 / 9之外,其他所有功能都可以正常工作。 The weird thing is, when I open the developer tools and console in IE to deb, and then refresh the page as it says to, the script runs fine. 奇怪的是,当我打开IE中的开发人员工具和控制台进行调试,然后刷新页面时,脚本运行正常。 What am I missing? 我想念什么? Any idea what IE doesn't like about this script? IE对此脚本不满意吗?

One other note - the script doesn't load until the window loads as I need to measure the height of images, so maybe that is part of the problem? 另一个注意事项-脚本要等到窗口加载时才加载,因为我需要测量图像的高度,所以这可能是问题的一部分吗?

Thanks for any help 谢谢你的帮助

$(window).load(function(){


     function offsetElement(element, container){
            if ( $(window).width() > 767 ) {

                $(element).each(function(index,value){

                    var snapImage = $(this),
                        snapImageHeight = snapImage.height(),
                        containerHeight = snapImage.closest(container).outerHeight(),
                        topOffset = (containerHeight - snapImageHeight) / 2;

                    $(this).css({ 'top' : topOffset });

                 });
            }

     }


        offsetElement('.snapshot', '.event');
        offsetElement('.dot', '.event'); 

    function activeSnap(){ return offsetElement('.snapshot', '.event'); }
    function activeDot(){ return offsetElement('.dot', '.event'); }


     $(window).resize(function(){
        activeSnap();
        activeDot();
     });


});

$(window).load() should be using the built in onload function so that shouldn't be the problem. $(window).load()应该使用内置的onload函数,所以这不是问题。 It could be your jQuery version, jQuery 2.X does not support Internet Explorer 6, 7, or 8. Make sure you're using jQuery 1.X for compatibility 可能是您的jQuery版本,而jQuery 2.X不支持Internet Explorer 6、7或8。请确保您使用的是jQuery1.X。

使用$(document).ready()代替$(window).load()

which over of jQuery are you using? 您使用的是哪种jQuery? have you try using window.onload see if IE works with it? 您是否尝试过使用window.onload看看IE是否可以使用它? – jasonslyvia 35 mins ago – jasonslyvia 35分钟前

Thanks @jasonslyvia, all I did was replace $(window).load for window.onload and it works fine now. 感谢@jasonslyvia,我所做的就是将$ {window).load替换为window.onload,现在可以正常使用了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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