jQuery不能在IE中运行

时间:2011-05-24 04:58:13

标签: jquery wordpress

我在Wordpress网站的Internet Explorer中运行我的jQuery脚本时遇到问题。在Firefox和Chrome上它运行顺畅,但IE不想和我一起玩。

我认为这可能是wordpress的jQuery中的冲突,因为我的脚本在简单的“$ variables”上工作得很好。我正在使用“jQuery变量”,就像他们在http://wordpress.org/support/topic/using-jquery-in-own-plugins#post-687280中说的那样,但在IE中仍然没有用。

任何人都可以告诉我如何在wordpress中正确包含我自己的jQuery文件?

非常感谢您的帮助。


function MoveItems() {
    jQuery('.container>div:first').animate({
        width: '0px'
    }, 1000, function () {
        var mine = jQuery(this);
        mine.parent().append(mine);
        jQuery(this).css({
            width: '120px'
        });
    });
    jQuery('#bands>h2:first').fadeTo(
    4000, 0, function () {
        var mine = jQuery(this);
        mine.parent().append(mine);
        jQuery(this).fadeTo(
        1, 1);
    });
};



jQuery(document).ready(function () {

    var timer = setInterval(MoveItems, 1000);

    jQuery('#sponsors').hover(function () {
        clearInterval(timer);
    }, function () {
        timer = setInterval(MoveItems, 1000);
    });

    jQuery('.sponsor').mouseover(function () {
        jQuery('img', this).animate({
            width: "200px",
            height: "200px",
            left: "-40px",
            top: "-40px"
        }, {
            queue: false,
            duration: 500
        });
    });

    jQuery('.sponsor').mouseleave(function () {
        jQuery('img', this).animate({
            width: "120px",
            height: "120px",
            left: "0px",
            top: "0px"
        }, {
            queue: false,
            duration: 500
        });
    });

});

4 个答案:

答案 0 :(得分:2)

好的,我有解决方案。在最新的wordpress版本中,jquery和ie8(有时是opera)存在一个已知错误。

有关此处的错误的更多信息:https://wordpress.stackexchange.com/questions/10719/jquery-in-ie8-no-longer-works-after-3-1-upgrade

解决方案:

//Making jQuery Google API
function modify_jquery() {
    if (!is_admin()) {
        // comment out the next two lines to load the local copy of jQuery
        wp_deregister_script('jquery');
        wp_register_script('jquery', 'https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js', false, '1.6.1');
        wp_enqueue_script('jquery');
    }
}
add_action('init', 'modify_jquery');

答案 1 :(得分:0)

首先尝试添加:

jQuery(document).ready(function($) { // When the document (page) has finished loading.

alert("jQuery is working!"); // Shows a window displaying "jQuery is working!"

}); 

并查看警报是否显示...如果显示警报,那么我认为它不是jquery问题

答案 2 :(得分:0)

将您认为可能与wordpress冲突的Jquery部分包含在

        jQuery.noConflict();
        (function($){

           // type your jquery here 

         })(jQuery) ;

看看它是否有效。

答案 3 :(得分:0)

IE不喜欢你分配一些变量的方式。它也可能是IE认为容器是一个全局变量。

看看这是否有帮助。 body可以是容器的任何父容器。

function MoveItems() {
    jQuery('body').append('.container>div:first').animate({
        width: '0px'
    }, 1000, function () {
        var mine = jQuery(this);
        mine.parent().append(mine);
        jQuery(this).css({
            width: '120px'
        });
    });
    jQuery('body').append('#bands>h2:first').fadeTo(
    4000, 0, function () {
        var mine = jQuery(this);
        mine.parent().append(mine);
        jQuery(this).fadeTo(
        1, 1);
    });
}  //removed this semi colon based on error from jslint.

jQuery(document).ready(function () {
    var timer = setInterval(MoveItems, 1000);
    jQuery('#sponsors').hover(function () {
        clearInterval(timer);
    }, function () {
        timer = setInterval(MoveItems, 1000);
    });

    jQuery('.sponsor').mouseover(function () {
        jQuery('img', this).animate({
            width: "200px",
            height: "200px",
            left: "-40px",
            top: "-40px"
        }, {
            queue: false,
            duration: 500
        });
    });

    jQuery('.sponsor').mouseleave(function () {
        jQuery('img', this).animate({
            width: "120px",
            height: "120px",
            left: "0px",
            top: "0px"
        }, {
            queue: false,
            duration: 500
        });
    });

}); 

这听起来很遥远,但我看到同样的错误因为注册表问题破坏了javascript引擎。

如果代码不起作用,请查看您是否可以在另一台运行IE的计算机上试用。

我还注意到你的所有javascript文件都有mime类型错误。可能不是导致这个问题的原因,而是需要注意的其他事项。

Resource interpreted as Script but transferred with MIME type application/octet-stream.
wp-scriptaculous.js:-1Resource interpreted as Script but transferred with MIME type application/octet-stream.
prototype.js:-1Resource interpreted as Script but transferred with MIME type application/octet-stream.
effects.js:-1Resource interpreted as Script but transferred with MIME type application/octet-stream.
lightbox.js:-1Resource interpreted as Script but transferred with MIME type application/octet-stream.
jquery.js:-1Resource interpreted as Script but transferred with MIME type application/octet-stream.
jquery.cycle.all.min.js:-1Resource interpreted as Script but transferred with MIME type application/octet-stream.
ngg.slideshow.min.js:-1Resource interpreted as Script but transferred with MIME type application/octet-stream.
webtoolkit.sprintf.js:-1Resource interpreted as Script but transferred with MIME type application/octet-stream.
fergcorp_countdownTimer_java.js:-1Resource interpreted as Script but transferred with MIME type application/octet-stream.
blink2_backup.js:-1Resource interpreted as Script but transferred with MIME type application/octet-stream.