jQuery不能像在其他浏览器中那样在Internet Explorer中工作

jQuery not working in Internet Explorer as it does in other browsers

本文关键字:工作 Internet Explorer 浏览器 不能 其他 jQuery      更新时间:2023-09-26

我正在建立一个个人网页,并把临时版本www.aegaeon.comule.com。我按照Dragon交互式教程(http://labs.dragoninteractive.com/pufferfish_article.php)制作了一个渐变背景的褪色悬停菜单。我将子页面安排为"面板",以便在单击相应的导航按钮时隐藏和显示。这是我的javascript/jQuery代码:

var color_text = '#999';
var color_text_hover = "#C0C0C0";
$(function(){
    $("div.panel:not(:first)").hide();  // hide all panels except the home panel
    var loc=window.location;
    window.location.replace(loc+"#home");   // make window location correspond to home panel
    var menu=$("#navbar a");
    menu.click(function(){
        var previous=window.location.hash;
        var selected=$(this).attr("href");
        if (previous != selected) {
            $("div.panel"+previous).fadeOut("slow")
            $("div.panel"+selected).fadeIn("slow");
            }
        menu.removeClass("selected");
        $(this).addClass("selected");
    });
    $('#navbar li a').append('<span class="hover"></span>')
    $('#navbar li a').hover(function() {

        if(!$(this).hasClass('selected')){
        // Stuff that happens when you hover on
        $('.hover', this).stop().animate({
            'opacity': 0.2
            }, 400)
            $(this).stop().animate({ 
                //backgroundColor: color_bg_hover,
                color: color_text_hover
            },400);
        }
    },function() {
        // Stuff that happens when you unhover
        $('.hover', this).stop().animate({
            'opacity': 0
            }, 700, 'easeOutSine')
        $(this).stop().animate({ 
                //backgroundColor: color_bg,
                color:color_text
            },700);
    })
});

在Chrome, Firefox和Safari中,该网站似乎运行良好,但在Internet Explorer中则不然。导航按钮最初是白色的,但当您将鼠标悬停在它们上面时,确实会变得可见,这表明javascript至少部分工作,但我无法解释不同的行为。

我看到很多分号缺失,例如:

        $("div.panel"+previous).fadeOut("slow")
        $("div.panel"+selected).fadeIn("slow");

检查你的代码

.stop()在ie中不起作用

代替鸡毛蒜皮().animate ({});使用.animate({你想要应用到元素的新动画。});