Requirejs jQuery正在覆盖WordPress加载的jQuery,我怎样才能避免这种情况(通过调用noCon

Requirejs jQuery is overriding the jQuery loaded by wordpress, how can i avoid that (by calling noConflict( true) )?

本文关键字:jQuery 情况 能避免 noCon 调用 WordPress 覆盖 加载 Requirejs      更新时间:2023-09-26

我在我的wordpress插件中使用require.js的jQuery版本,但是requirejs的jQuery覆盖了WordPress加载的jQuery。如何告诉requirejs使用的jQuery调用自身noConflict( true ),这样它就不会覆盖wordpress加载的版本?

最后我做了这样的事情:

创建这样的配置文件

requirejs.config( {
    "paths": { 
        "jquery": "require_jquery"
    },
    "shim": {
        "jquery-cookie"  : ["jquery"],
        "bootstrap-tab"  : ["jquery"],
        "bootstrap-modal": ["jquery"],
        "bootstrap-alert": ["jquery"]
    }
} );

创建一个这样的require_jquery.js文件

define(["jquery-1.7.2"], function() {
    // Raw jQuery does not return anything, so return it explicitly here.
    return jQuery.noConflict( true );
})

然后像往常一样使用 jquery。一切正常,jQuery的外部版本保持不变。