在IE浏览器中的javascript错误

问题描述:

我需要关于IE6 +中获得的错误消息的帮助。 请注意,代码工作正常。在IE浏览器中的javascript错误

消息:预期的对象
线:38
字符:4
代码:0
URI:http://localhost/dropbox/panorama/index.php?lang=gr

什么实际上是在第38行是这样的:

<script type="text/javascript"> 
    $(document).ready(function(){ 
     slideShow(); 
    }); 
</script> 

LINE 38是我打电话给我的“slideShow()”函数
还要注意这些函数存储在外部文件中。

这些是外部文件的内容:

$(function slideShow() { 
    //Set the opacity of all images to 0 
    $('#gallery li').css({opacity: 0.0}); 

    //Get the first image and display it (set it to full opacity) 
    $('#gallery li:first').css({opacity: 1.0}); 

    //Call the gallery imgGallery to run the slideshow, 5000: 5 seconds interval 
    setInterval('imgGallery()',4000); 
}); 

$(function imgGallery() { 
    //Get the first image 
    var current = ($('#gallery li.show')? $('#gallery li.show') : $('#gallery li:first')); 

    //Get next image, if reached last image, start over from the first image 
    var next = ((current.next().length) ? (current.next()) : $('#gallery li:first')); 


    //Set the fade in effect for the next image 
    next.css({opacity: 0.0}) 
     .addClass('show') 
     .animate({opacity: 1.0}, 1000); 

    //Hide current image 
    current.animate({opacity: 0.0}, 1000) 
     .removeClass('show'); 
}); 

任何建议?

+0

你是否参考了jQuery库? – WraithNath 2011-04-08 10:54:03

+0

是的,我确定。我也导入了外部js文件 – george 2011-04-08 11:01:23

+0

好吧,不得不问!什么是你的slideShow();方法? – WraithNath 2011-04-08 11:02:25

试着和setInterval(imgGallery,4000);
更换setInterval('imgGallery()',4000);如果不工作,这应该:
setInterval(function(){imgGallery();},4000)

的方式即参考行号并不总是100%,取决于如何/如果包含该文件。无论如何评论幻灯片放映功能中的所有代码,并查看它是否仍然会抛出错误,如果确实行号实际上指向其他内容。

如果不一致,则每次将每行返回1,直到发生错误。

可悲的是,这是我在IE6

一个由保罗爱尔兰报价知道调试的最佳方式:“setInterval的是一个混蛋!”来自Paul Irish:我从jQuery Source学到的10件事。 http://vimeo.com/12529436

快进到07:40并持续约5分钟。使用setInterval的Intead可以使用setTimeout并调用它自己。

您将函数幻灯片和imgGallery包装在一个jQuery对象中。

$(function slideShow(){ 

} 

$(function imgGallery() { 
    ... 
}); 

这意味着他们将不会在全球范围内。删除$(),因为它不是必需的。

+0

epascarello,我做了你的建议,但我没有工作。但是,当我将这两个函数放在我调用它们的同一个文件中时,它就起作用了。那么,现在,我想把这两个函数放在一个单独的文件中,然后导入它?我怎样才能做到这一点?谢谢 – george 2011-04-08 13:38:29

+0

恩,你确定文件正在加载吗? – epascarello 2011-04-08 14:04:55

+0

我只是把一个简单的警报命令放在外部文件上,并没有执行。嗯,这意味着文件没有加载哈?我猜你是对的。 js文件的路径是正确的!我不知道 – george 2011-04-08 14:17:32