【问题标题】:Wordpress Plugin jQuery ConflictsWordpress 插件 jQuery 冲突
【发布时间】:2014-09-23 19:42:42
【问题描述】:

我正在开发一个插件,我无法摆脱网站中的 jquery 冲突,我想在插件中包含我自己的 jquery 和自定义脚本即使主题已经使用 jquery,也可以完全使用 jquery以仅影响插件的不同方式?

现在我有了这个,但它们与主题 jquery 和脚本发生冲突,我如何完全分离插件 jquery,我的意思是仅用于插件?

    function il_style() {

    wp_register_script( 'il_admin_jquery_script', plugins_url( '/il_js/jquery-1.11.0.min.js' , __FILE__, true));
    wp_register_script( 'il_admin_jquery_forms_styler_script', plugins_url( '/il_js/jquery.formstyler.min.js' , __FILE__, true));
    wp_register_script( 'il_admin_custom_jquery_script', plugins_url( '/il_js/il.jquery.custom.js' , __FILE__, true));
    wp_register_script( 'il_custom_jquery_forms', plugins_url( '/il_js/il.jquery.forms.js' , __FILE__, true));
    wp_register_script( 'il_custom_jquery_captcha', plugins_url( '/il_js/QapTcha.jquery.js' , __FILE__, true));
    wp_register_script( 'il_custom_jquery_captcha_touch', plugins_url( '/il_js/jquery.ui.touch.js' , __FILE__, true));

    wp_enqueue_scripts('il_admin_jquery_script');
    wp_enqueue_scripts('il_admin_jquery_forms_styler_script');
    wp_enqueue_scripts('il_admin_custom_jquery_script');
    wp_enqueue_scripts('il_custom_jquery_forms');
    wp_enqueue_scripts('il_custom_jquery_captcha');
    wp_enqueue_scripts('il_custom_jquery_captcha_touch');
}
add_action( 'init', 'il_style' );

【问题讨论】:

标签: jquery wordpress


【解决方案1】:

那么您是说您希望能够删除 jquery 的用户副本并在您的插件中使用您自己的副本?

如果是这样,您当然应该检查用户是否已经在他们的网站上运行并使用了 jquery?

如果一个插件覆盖了我自己的副本,我会很生气。

【讨论】:

  • 我完全同意,但我有特定的东西只能用 jquery 1.11 运行,我无法摆脱冲突。在这种情况下你可以给我什么建议? @jamespayne
  • 就我个人而言,我会使用旧版本的 jQuery 并调整我的代码以适应 - 如果你真的不能没有最新版本,你需要将标准版本出列并加入你的版本,虽然这将是一个雷区,因为并非每个人都以标准方式使用 jQuery。例如,出于速度/延迟原因,我将内置 jQuery 出列并从 Google CDN 运行它。
猜你喜欢
  • 2012-11-14
  • 2011-06-18
  • 1970-01-01
  • 1970-01-01
  • 2014-03-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多