【问题标题】:Simple Custom jQuery Rotator Not Working in IE 7, 8, or 9简单的自定义 jQuery 旋转器在 IE 7、8 或 9 中不起作用
【发布时间】:2013-06-09 09:49:02
【问题描述】:

这是我的 jsFiddle:http://jsfiddle.net/markrummel/vPcrX/

此代码适用于 Chrome、Firefox、Safari 和 IE 10,但不适用于 IE 7、8 或 9。

我已经通过 IE 10 的开发者工具对其进行了测试,当我第一次在 IE 7、8 或 9 中打开它时它不起作用。但是,在我打开开发者工具后它开始在 IE 7、8 和 IE 中工作9. 我也通过Microsoft's Virtual PC在旧的IE浏览器中测试过,旋转器不工作。

您可以在此处查看整个页面:http://melaniejaderummel.com。但是,我认为这个问题与 jQuery 代码无关,因为它在精简的jsFiddle 中不起作用。

我们将不胜感激您能提供的任何帮助!

我的 HTML:

<div id="testimonials">
    <p data-testimonial="1">“Testimonial Content” – Julie S.</p>
    <p data-testimonial="2">“Testimonial Content” – Melissa D.</p>
    <!--repeated; 10 total testimonials-->
</div>

相关的 CSS:

#testimonials p {display:none;}

最后,这是我的 javascript:

$(document).ready(function () {

    var shownTestimonials = [];

    displayTestimonials(shownTestimonials);

    function displayTestimonials(shownTestimonials) {
        var totalTestimonials = 10;

        console.log(shownTestimonials);
        //console.log(shownTestimonials.length);

        if (shownTestimonials.length == 0 || shownTestimonials.length == totalTestimonials) {
            var shownTestimonials = [];
        }

        function getNewTestimonial(totalTestimonials) {
            return Math.floor(Math.random() * totalTestimonials) + 1; //random number between 1 and 10
        }

        var currentTestimonial = $('#testimonials p.visible').attr('data-testimonial');
        var newTestimonial = getNewTestimonial(totalTestimonials);

        console.log(currentTestimonial);

        if (currentTestimonial == null) {
            $('#testimonials p[data-testimonial="' + newTestimonial + '"]').addClass('visible').fadeIn(700);
            shownTestimonials.push(newTestimonial);
        } else {

            var newExists = 1;

            while (newExists > -1) {
                var newTestimonial = getNewTestimonial(totalTestimonials);
                var newExists = $.inArray(newTestimonial, shownTestimonials)
                console.log(newExists);
            }

            $('#testimonials p[data-testimonial="' + currentTestimonial + '"]').removeClass('visible').fadeOut(600);
            setTimeout(function () {
                $('#testimonials p[data-testimonial="' + newTestimonial + '"]').addClass('visible').fadeIn(700);
                shownTestimonials.push(newTestimonial);
            }, 700);
        } //end else

        setTimeout(function () {
            displayTestimonials(shownTestimonials);
        }, 12000);
    } //end displayTestimonials();

}); //end $(document).ready

【问题讨论】:

    标签: jquery internet-explorer cross-browser show-hide


    【解决方案1】:

    删除或注释掉console.log 语句。除非控制台打开(在具有开发工具的 IE 版本中),否则 IE 会阻塞它们。

    this MSDN article:

    请记住,除非您有 开发者工具打开。您可以在任一 控制台或脚本选项卡。使用控制台进行调试时要小心。 如果您在移动时在代码中留下对控制台对象的调用 到生产环境并且您没有向您展示开发人员工具 将收到一条错误消息,告诉您控制台未定义。为避免出现错误消息,您要么需要从代码中删除所有控制台方法调用,要么需要在调用任何方法之前添加检查以确保控制台存在。

    【讨论】:

    • 有效!我注释掉了console.log 代码行。一百万年后,我自己也想不通。谢谢!另外,感谢 MSDN 参考。在进入生产阶段时,我一定会摆脱我的console.log 行。再次感谢!
    猜你喜欢
    • 1970-01-01
    • 2011-11-30
    • 2012-11-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多