codeigniter 如何在perfex CRM中添加jquery?

s1ag04yj  于 2022-12-07  发布在  jQuery
关注(0)|答案(1)|浏览(139)

每次我尝试使用cdn链接添加jquery,甚至从我的模块中的资产加载它时,它都会与perfex crm默认的jquery冲突。我该怎么办?
我尝试在我的模块中添加jquery,如下所示:

hooks()->add_filter('before_compile_css_assets',function(){
   // include 'assets/jquery.js';
   echo "<script src='https://code.jquery.com/jquery-3.1.0.min.js' ></script>";
  });

// or like this 

 hooks()->add_filter('before_compile_scripts_assets',function(){
   // include 'assets/jquery.js';
   echo "<script src='https://code.jquery.com/jquery-3.1.0.min.js' ></script>";
  });
zdwk9cvp

zdwk9cvp1#

让我们假设我模块名称是woocommerce

//for app admin footer (if you want to add in footer)
        hooks()->add_action('app_admin_footer', 'woocommerce_load_js');
        function woocommerce_load_js()
        {
            echo "<script src='https://code.jquery.com/jquery-3.1.0.min.js' ></script>";
        }

// for app admin head (if you want to add in header)
    hooks()->add_action('app_admin_head', 'woocommerce_load_js');
    function woocommerce_load_js()
    {
        echo "<script src='https://code.jquery.com/jquery-3.1.0.min.js' ></script>";
    }

现在,添加jquery后,您可以使用如下代码

<script>
$.noConflict();
jQuery(document).ready(function($){
  $("button").click(function(){
    $("p").text("jQuery is still working!");
  });
});
</script>

相关问题