繁体   English   中英

将jquery放入wordpress中?

[英]Enqueue jquery in wordpress?

我在将jquery库添加到自定义wordpress插件时遇到了一些麻烦。 它告诉我找不到变量jQuery。 任何帮助深表感谢。

simplepluginclass.php包含functions.php

include plugin_dir_path( __FILE__ ) . 'inc/functions.php';

functions.php

 <?php
        function register_jqscripts() {
            wp_enqueue_script('jQuery', 'http://code.google.com/apis/libraries/devguide.html#jquery');
            wp_enqueue_script('jquery-ui-core', 'https://code.jquery.com/ui/1.12.1/jquery-ui.min.js');
            wp_enqueue_script('jquery-ui-datepicker');
            wp_enqueue_style('jquery-ui-css', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/smoothness/jquery-ui.css');
        }


    function add_datepicker(){ ?>
    <script type="text/javascript">
    jQuery(document).ready(function(){
        jQuery('#dob').datepicker({
            dateFormat: 'dd-mm-yy'
        });
    });
    </script>
    <?php
    }
    add_action( 'register_form', 'register_jqscripts' );
    add_action('register_form','add_datepicker');

?>

simplepluginclass.php

 <label for="dob"><?php _e( 'Date of Birth', 'sportspress' ) ?><br />
               <input type="date" class="customdatepicker" id="dob" name="dob" />
          </label>

您为jQuery引用的链接指向Google Code文档。 更改链接以指向CDN上的jQuery源文件:

wp_enqueue_script('jQuery', 'https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js');

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM