本文介绍了jQuery选择器在IE8中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
此代码导致第二行($('boxes div.box'))错误
This code results in an error at second line ($('boxes div.box'))
<script type="text/javascript">
$(document).ready(function () {
boxes = $('#boxes div.box');
images = $('#images > div');
boxes.each(function (idx) {
$(this).data('image', images.eq(idx));
}).hover(
function () {
boxes.removeClass('active');
images.removeClass('active');
$(this).addClass('active');
$(this).data('image').addClass('active');
});
});
</script>
错误为对象不支持此属性或方法" .在Firefox和Chrome中,同一页面可以正常工作.
The error is "Object doesn't support this property or method". The same page works fine in Firefox and Chrome.
有人吗?
推荐答案
您需要使用var
关键字声明变量,否则IE不知道它们的来源,因此会中断:
You need to declare variables with the var
keyword, otherwise IE has no idea where they're coming from and so will just break:
var boxes = $('#boxes div.box');
var images = $('#images > div');
这篇关于jQuery选择器在IE8中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!