下面是我正在尝试使用jquery datetime选择器的自定义插件的页面代码。选取器脚本取自this link。但是由于某种原因,我收到一条错误消息,说"jQuery("#calendar1,#calendar2").calendar不是一个函数“。我已经检查了所需的文件是否正确包含在自定义代码之前。但是仍然有这个错误。
<?php
function list_my_styles() { // ADDING THE SCRIPTS
$plugin_url = WP_PLUGIN_URL.'/my_custom_datepicker/';
wp_register_style('my-addon-datepicker-css',$plugin_url.'jquery-calendar.css');
wp_enqueue_style('my-addon-datepicker-css');
wp_enqueue_script('jquery');
wp_register_script('calendar_plugin',$plugin_url.'jquery-calendar.js');
wp_enqueue_script('calendar_plugin');
}
add_action('wp_enqueue_scripts','list_my_styles');
function my_custom_datetime_script() { // ADDING THE JQUERY SCRIPT
?>
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery("#calendar1, #calendar2").calendar();
jQuery("#calendar1_alert").click(function(){alert(popUpCal.parseDate(jQuery('#calendar1').val()))});
});
</script>
<?php
}
add_action('wp_head','my_custom_datetime_script');
function custom_datetime_picker_area() {
?>
<input type="text" id="calendar1" class="calendarFocus"/>
<input type="button" id="calendar1_alert" value="Alert datetime object"/>
<?php
}
add_shortcode('my_datepicker','custom_datetime_picker_area');
?>任何帮助我们都将不胜感激。
谢谢
发布于 2012-11-22 05:25:45
这是我在插件中使用的:
/* add jquery ui datepicker and theme */
global $wp_scripts;
wp_enqueue_script('jquery-ui-datepicker');
$ui = $wp_scripts->query('jquery-ui-core');
$url = "https://ajax.aspnetcdn.com/ajax/jquery.ui/{$ui->ver}/themes/redmond/jquery.ui.all.css";
wp_enqueue_style('jquery-ui-redmond', $url, false, $ui->ver);我使用的CDN也有所有可用的主题可供选择。
然后在我的表单页面上,我使用:
<label for="date_of" style="width: 135px !important;">Presentation Date
<?php echo '<img src="'.$this->pluginurl.'images/help.png"
title="Enter the Presentation date here." />';?>
</label>
<input type="text" id="date_of" name="date_of" value="" />以及在以下位置:
jQuery(document).ready(function() {
jQuery('#date_of').datepicker({
dateFormat: 'yy-mm-dd'
});
});我使用包含document.ready函数的register/enqueue_script加载plugin.js文件。
希望这能有所帮助。
发布于 2012-08-27 21:30:56
该错误表示它找不到此函数,这反过来又意味着:1-找不到脚本,或者2-您正在尝试在加载脚本之前执行脚本。
有一件事我不明白--这段代码在你的插件里放到哪里去了?
无论如何,首先验证你的主题中有一个wp_head()和wp_head()动作(模板标签),然后,也试着把动作移到页脚……
function my_custom_datetime_script() { // ADDING THE JQUERY SCRIPT
?>
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery("#calendar1, #calendar2").calendar();
jQuery("#calendar1_alert").click(function(){alert(popUpCal.parseDate(jQuery('#calendar1').val()))});
});
</script>
<?php
}
add_action('wp_footer','my_custom_datetime_script');https://stackoverflow.com/questions/12141598
复制相似问题