IE8 错误与具有 jQuery 函数的 javascript 文件?

发布于 2024-09-17 09:23:31 字数 4313 浏览 0 评论 0原文

我在 IE8 中遇到此错误:

Page Error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; GTB6.5;. NET CLR 1.1.4322;. NET CLR 2.0.50727;. NET CLR 3.0.04506.30;. NET CLR 3.0.4506.2152;. NET CLR 3.5.30729;. NET4.0C)
Timestamp: Wed, 1 Sep 2010 11:15:04 UTC


Message: Object does not support this property or method
Row: 10
Character: 2
Code: 0
URI: http://widerdesign.com.tw/wp-content/themes/starkers/js/custom.js

custom.js:

$(document).ready(function () {
    //easy slider
    $('ul.sf-menu').superfish();
    //easy slider
    $("#slider").easySlider({
        auto: true,
        continuous: true
    });
    //fancybox
    $("a#showcase1").attr('rel', 'gallery').fancybox({
        'scrolling' : 'no',
        'titleShow' : false
    });

    $("a#showcase2").attr('rel', 'gallery').fancybox({
        'scrolling' : 'no',
        'titleShow' : false
    });

    $("a#showcase3").attr('rel', 'gallery').fancybox({
        'scrolling' : 'no',
        'titleShow' : false
    });

    $("a#showcase4").attr('rel', 'gallery').fancybox({
        'scrolling' : 'no',
        'titleShow' : false
    });

    $("a#showcase5").attr('rel', 'gallery').fancybox({
        'scrolling' : 'no',
        'titleShow' : false
    });

    $("a#showcase6").attr('rel', 'gallery').fancybox({
        'scrolling' : 'no',
        'titleShow' : false
    });

    $("a#showcase7").attr('rel', 'gallery').fancybox({
        'scrolling' : 'no',
        'titleShow' : false
    });

    $("a#showcase8").attr('rel', 'gallery').fancybox({
        'scrolling' : 'no',
        'titleShow' : false
    });

    $("a#showcase9").attr('rel', 'gallery').fancybox({
        'scrolling' : 'no',
        'titleShow' : false
    });
});

header.php 中的头标记

<head>
<meta charset="<?php bloginfo( 'charset' ); ?>" />
<title><?php
    /*
     * Print the <title> tag based on what is being viewed.
     * We filter the output of wp_title() a bit -- see
     * twentyten_filter_wp_title() in functions.php.
     */
    wp_title( '|', true, 'right' );

    ?></title>
<link rel="profile" href="http://gmpg.org/xfn/11" />
<link rel="stylesheet" type="text/css" media="all" href="<?php bloginfo( 'stylesheet_url' ); ?>" />
<link rel="stylesheet" type="text/css" href="<?php bloginfo('template_directory'); ?>/css/slider.css" />
<link rel="stylesheet" type="text/css" href="<?php bloginfo('template_directory'); ?>/css/superfish.css" />
<link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>" />

<?php
    /* We add some JavaScript to pages with the comment form
     * to support sites with threaded comments (when in use).
     */
    if ( is_singular() && get_option( 'thread_comments' ) )
        wp_enqueue_script( 'comment-reply' );

    /* Always have wp_head() just before the closing </head>
     * tag of your theme, or you will break many plugins, which
     * generally use this hook to add elements to <head> such
     * as styles, scripts, and meta tags.
     */
    wp_head();
?>
</head>

页脚包含 js 文件:

</div><!-- #footer -->
<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/custom.js"></script>
<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/easySlider1.5.js"></script>
<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/superfish.js"></script>
<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/jquery-1.2.6.min.js"></script>
<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/hoverIntent.js"></script>
<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/superfish.js"></script>
</body>
</html>

有什么建议吗?

该代码可以在 Chrome 和 Firefox 上正常运行(如预期)

I'm getting this error in IE8:

Page Error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; GTB6.5;. NET CLR 1.1.4322;. NET CLR 2.0.50727;. NET CLR 3.0.04506.30;. NET CLR 3.0.4506.2152;. NET CLR 3.5.30729;. NET4.0C)
Timestamp: Wed, 1 Sep 2010 11:15:04 UTC


Message: Object does not support this property or method
Row: 10
Character: 2
Code: 0
URI: http://widerdesign.com.tw/wp-content/themes/starkers/js/custom.js

custom.js:

$(document).ready(function () {
    //easy slider
    $('ul.sf-menu').superfish();
    //easy slider
    $("#slider").easySlider({
        auto: true,
        continuous: true
    });
    //fancybox
    $("a#showcase1").attr('rel', 'gallery').fancybox({
        'scrolling' : 'no',
        'titleShow' : false
    });

    $("a#showcase2").attr('rel', 'gallery').fancybox({
        'scrolling' : 'no',
        'titleShow' : false
    });

    $("a#showcase3").attr('rel', 'gallery').fancybox({
        'scrolling' : 'no',
        'titleShow' : false
    });

    $("a#showcase4").attr('rel', 'gallery').fancybox({
        'scrolling' : 'no',
        'titleShow' : false
    });

    $("a#showcase5").attr('rel', 'gallery').fancybox({
        'scrolling' : 'no',
        'titleShow' : false
    });

    $("a#showcase6").attr('rel', 'gallery').fancybox({
        'scrolling' : 'no',
        'titleShow' : false
    });

    $("a#showcase7").attr('rel', 'gallery').fancybox({
        'scrolling' : 'no',
        'titleShow' : false
    });

    $("a#showcase8").attr('rel', 'gallery').fancybox({
        'scrolling' : 'no',
        'titleShow' : false
    });

    $("a#showcase9").attr('rel', 'gallery').fancybox({
        'scrolling' : 'no',
        'titleShow' : false
    });
});

head tags in header.php

<head>
<meta charset="<?php bloginfo( 'charset' ); ?>" />
<title><?php
    /*
     * Print the <title> tag based on what is being viewed.
     * We filter the output of wp_title() a bit -- see
     * twentyten_filter_wp_title() in functions.php.
     */
    wp_title( '|', true, 'right' );

    ?></title>
<link rel="profile" href="http://gmpg.org/xfn/11" />
<link rel="stylesheet" type="text/css" media="all" href="<?php bloginfo( 'stylesheet_url' ); ?>" />
<link rel="stylesheet" type="text/css" href="<?php bloginfo('template_directory'); ?>/css/slider.css" />
<link rel="stylesheet" type="text/css" href="<?php bloginfo('template_directory'); ?>/css/superfish.css" />
<link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>" />

<?php
    /* We add some JavaScript to pages with the comment form
     * to support sites with threaded comments (when in use).
     */
    if ( is_singular() && get_option( 'thread_comments' ) )
        wp_enqueue_script( 'comment-reply' );

    /* Always have wp_head() just before the closing </head>
     * tag of your theme, or you will break many plugins, which
     * generally use this hook to add elements to <head> such
     * as styles, scripts, and meta tags.
     */
    wp_head();
?>
</head>

included js files on footer:

</div><!-- #footer -->
<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/custom.js"></script>
<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/easySlider1.5.js"></script>
<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/superfish.js"></script>
<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/jquery-1.2.6.min.js"></script>
<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/hoverIntent.js"></script>
<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/superfish.js"></script>
</body>
</html>

any suggestions?

The code is properly working on Chrome and Firefox (as expected)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

遥远的绿洲 2024-09-24 09:23:32

您将包含 jQuery 两次,这将清除其上定义的所有插件,因为它定义了 $$.fn (在 document .ready 触发)。要修复它,只需使用一个版本的 jQuery(一个页面中的多个版本不能很好地发挥作用,它们的设计初衷并非如此)。

我认为你的页脚总体上应该是这样的:

</div><!-- #footer -->
<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/easySlider1.5.js"></script>
<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/superfish.js"></script>
<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/hoverIntent.js"></script>
<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/custom.js"></script>
</body>
</html>

You are including jQuery twice, which will wipe out any plugins defined on it since it defines $ and $.fn (before document.ready fires). To fix it only use one version of jQuery (multiple versions in a page do not play nicely, they're not designed to).

I think your footer should look like this overall:

</div><!-- #footer -->
<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/easySlider1.5.js"></script>
<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/superfish.js"></script>
<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/hoverIntent.js"></script>
<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/custom.js"></script>
</body>
</html>
╰◇生如夏花灿烂 2024-09-24 09:23:32

我首先删除对 superfish 和 jquery 的额外引用。 IE 的处理方式可能与其他浏览器不同。

我认为它应该是这样的:

<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/easySlider1.5.js"></script>
<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/superfish.js"></script>
<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/hoverIntent.js"></script>
<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/custom.js"></script>

I would start by removing the extra references to superfish and jquery. IE may be handling those differently than the other browsers.

Here's what I think it should look like:

<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/easySlider1.5.js"></script>
<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/superfish.js"></script>
<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/hoverIntent.js"></script>
<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/custom.js"></script>
清欢 2024-09-24 09:23:32

看起来你还没有包含 jQuery 文件?它需要显示在您的页面上,作为包含您自己的文件的行上方的包含内容。

It looks like you haven't included the jQuery file as well? It needs to appear on your page as an include above the line that includes your own file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文