开发者

jquery selector not working in IE8

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>

The error is "Object doesn't 开发者_JAVA百科support this property or method". The same page works fine in Firefox and Chrome.

Anyone?


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');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜