jQuery选择器在IE8中不起作用 [英] jquery selector not working in IE8

查看:115
本文介绍了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中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆