jQuery 无法在 IE 中运行

发布于 2024-11-09 04:18:44 字数 1750 浏览 0 评论 0原文

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

我认为这在 WordPress 的 jQuery 中可能会发生冲突,因为我的脚本在简单的“$variables”上运行良好。我正在使用“jQueryvariable”,就像他们在 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
        });
    });

});

i have a problem with running my jQuery scripts in Internet Explorer at my Wordpress sites. On Firefox and Chrome it is working smoothly, but IE does not want to play with me.

I think that this can be conflict in wordpress's jQuery because my script is working well on simple "$variables". I'am using "jQueryvariable" like they saying in http://wordpress.org/support/topic/using-jquery-in-own-plugins#post-687280 but in IE is still not working.

Anyone can tell me how to include my own jQuery files in wordpress properly?

Thank You very much for help.


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
        });
    });

});

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

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

发布评论

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

评论(4

小情绪 2024-11-16 04:18:44

好的,我有解决方案。在最新的 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');

OK i have the solution. There is a know error with jquery and ie8 (sometimes opera) in latest wordpress releases.

more about error here: https://wordpress.stackexchange.com/questions/10719/jquery-in-ie8-no-longer-works-after-3-1-upgrade

SOLUTION:

//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');
萌化 2024-11-16 04:18:44

尝试先添加此:

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

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

}); 

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

Try to add this first :

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

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

}); 

and see whether alert is display or not...If alert is display then its not jquery issue i think

好多鱼好多余 2024-11-16 04:18:44

附上您认为可能与 WordPress 冲突的 Jquery 部分,

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

           // type your jquery here 

         })(jQuery) ;

看看它是否有效。

Enclose the part of Jquery that you think, might be conflicting with wordpress into

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

           // type your jquery here 

         })(jQuery) ;

see if it works.

青丝拂面 2024-11-16 04:18:44

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
        });
    });

}); 

这听起来很牵强,但我在 Ie 上看到过同样的错误,这是由于注册表问题破坏了 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.

IE doesn't like the way your assigning some of the variables. It could also be that IE thinks container is a global variable.

See if this helps. body can be any parent container of container.

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
        });
    });

}); 

It sounds far fetched but I've seen the same error on Ie caused by registry problems corrupting the javascript engine.

If the code doesn't work see if you can try it on another computer running IE.

I also noticed you have mime type errors for all your javascript files. Might not be the cause of this problem but something else to take a look at.

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