像这样改变。注意代码中月份的增量,否则需要在invalidMonths数组中定义为'month-1'。
var invalidMonths = [11,12,1,2];
function noInvalidMonths(date)
{
var month = eval(date.getMonth()+1); //increment by 1 since the months start from 0
if (jQuery.inArray(month, invalidMonths) != -1) {
return [false];
}
return [true];
}
jQuery(function($) {
$("#date1").datepicker({
minDate: 0,
maxDate: null,
dateFormat: 'MM dd, yy',
beforeShowDay: noInvalidMonths
});
});
更新:
停用您的“联系表 7 日期选择器”插件,将联系表中的“日期选择器”都更改为“文本”框。将以下内容添加到主题的“functions.php”中。
function wp_custom_enqueue_datepicker() {
// Load the datepicker script (pre-registered in WordPress).
wp_enqueue_script( 'jquery-ui-datepicker', array( 'jquery' ) );
wp_register_style('jquery-ui', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css');
wp_enqueue_style( 'jquery-ui' );
wp_add_inline_script( 'jquery-ui-datepicker', 'var invalidMonths = [11,12,1,2]; function noInvalidMonths(date) { var month = eval(date.getMonth()+1); if (jQuery.inArray(month, invalidMonths) != -1) { return [false]; } return [true]; } jQuery(function($) { $("#date1,#date2").datepicker({ minDate: 0, maxDate: null, dateFormat: \'MM dd, yy\', beforeShowDay: noInvalidMonths }); var $date1 = $(\'#date1\'), $date2 = $(\'#date2\'); $date1.datepicker(\'option\', \'onSelect\', function(value){ $date2.datepicker(\'option\', \'minDate\', value); }); });' );
}
add_action( 'wp_enqueue_scripts', 'wp_custom_enqueue_datepicker' );