Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/429.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript IE8中的jQuery未定义变量_Javascript_Jquery_Undefined - Fatal编程技术网

Javascript IE8中的jQuery未定义变量

Javascript IE8中的jQuery未定义变量,javascript,jquery,undefined,Javascript,Jquery,Undefined,我已经为slider创建了一个jQuery小脚本。它在Firefox、Chrome、IE9中工作得非常好,但当我停留在IE7、IE8中时。显示警报错误(未定义的当前悬停项) 我尝试删除(var)关键字,但当我悬停时,它不会显示所有内容。 请帮帮我。谢谢。第二个函数中未定义当前的悬停项,因为第一个函数中的定义在一个函数中 您需要在这两个函数中声明current\u hover\u item。或者,由于在每个函数中只使用一次变量,请将其完全删除,如下所示: $('.nav-item').hover(

我已经为slider创建了一个jQuery小脚本。它在Firefox、Chrome、IE9中工作得非常好,但当我停留在IE7、IE8中时。显示警报错误(未定义的当前悬停项)

我尝试删除(var)关键字,但当我悬停时,它不会显示所有内容。
请帮帮我。谢谢。

第二个函数中未定义当前的悬停项,因为第一个函数中的定义在一个函数中

您需要在这两个函数中声明
current\u hover\u item
。或者,由于在每个函数中只使用一次变量,请将其完全删除,如下所示:

$('.nav-item').hover(function(){
        $('.show-item').hide();
        $($(this).children().attr('rel')).fadeIn(1000);
        $(this).animate({"width": "+=10px", opacity: 0.6}, 500, function(){
             $(this).animate({"width": "-=10px", opacity: 1}, 500);
        });
}, function(){
        $($(this).children().attr('rel')).fadeOut(1000);
        return false;
});

或者最好重构代码。

今天早些时候我遇到了这个问题。我通过在任何jquery函数(包括.ready())之外声明变量,然后在需要它的地方(当前声明它的地方)设置它来修复它

谢谢。我试过你的代码,但在我的上下文中,它不起作用。
$('.nav-item').hover(function(){
        $('.show-item').hide();
        $($(this).children().attr('rel')).fadeIn(1000);
        $(this).animate({"width": "+=10px", opacity: 0.6}, 500, function(){
             $(this).animate({"width": "-=10px", opacity: 1}, 500);
        });
}, function(){
        $($(this).children().attr('rel')).fadeOut(1000);
        return false;
});