【发布时间】:2012-04-26 12:24:20
【问题描述】:
此代码导致第二行出错 ($('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 中运行良好。
有人吗?
【问题讨论】:
-
你的
<script>标签是什么样的,你在哪里包含jQuery? -
在很多情况下这是一个假设...如果您知道问题的根源,您为什么要问这个问题?脚本包含了这个原因,因为细微的差异只会影响 IE,千万不要假设!
标签: javascript jquery jquery-selectors