【问题标题】:Wordpress how to add jquery to Moodle projectWordpress 如何将 jquery 添加到 Moodle 项目
【发布时间】:2021-11-06 07:29:12
【问题描述】:

我正在尝试将jquery 添加到我的moodle 项目中

我将此添加到additional.html

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui-touch-punch/0.2.3/jquery.ui.touch-punch.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">

我不断收到错误 $ is not defined 为什么?

你能解释一下吗?

【问题讨论】:

    标签: jquery wordpress wordpress-theming moodle custom-wordpress-pages


    【解决方案1】:

    首先确保jquery 已加载到您的页面上。把它放在你的functions.php

    add_action('wp_enqueue_scripts', 'enqueue_my_files');
    function enqueue_my_files(){
      wp_enqueue_script('jquery');
    }
    

    在您的 javascript 部分中,使用此语法定义 $,然后在其中编写您的 jquery 代码

    jQuery(document).ready( function($){
    
      // you could put your jquery code in here!
    
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-12-15
      • 1970-01-01
      • 2013-10-26
      • 2010-10-28
      • 1970-01-01
      • 1970-01-01
      • 2010-11-24
      相关资源
      最近更新 更多