[英]Date picker with disable dates JQuery UI issue
I need to update the disabled dates of a UI Jquery datepicker when a different city is chosen from a combo box, so what iv done is onchange of the combo box run the following function which does an ajax call to a php script which hits the DB via sql and returns the dates based on the city whcih i dump into the unavalibledates variable and rerun the .datepicker 当从组合框中选择其他城市时,我需要更新UI Jquery datepicker的禁用日期,因此在iv做的是组合框的onchange运行以下函数,该函数对PHP脚本进行ajax调用,从而击中数据库通过SQL并返回基于城市的日期,我将城市转储到unavalibledates变量中并重新运行.datepicker
This only works the first time its run, after which is does not update, but does not error. 这仅在第一次运行时有效,此后不会更新,但不会出错。 how do I make it update.
我如何使其更新。
function update_datepicker()
{
$.ajax({
type: "POST",
url: "scripts/deals.php?val=05&city="+document.getElementById('city_combo').value,
success: function (temp2)
{
var unavailableDates = [eval(temp2)];
function unavailable(date) {
dmy = date.getDate() + "-" + (date.getMonth()+1) + "-" + date.getFullYear();
if ($.inArray(dmy, unavailableDates) == -1) {
return [true, ""];
} else {
return [false,"","Unavailable"];
}
}
$('#datepicker').datepicker({ beforeShowDay: unavailable });
}
});
}
do not create every time a new datepicker, just update your current 不要每次都创建一个新的日期选择器,只需更新您当前的
var unavailableDates;
function unavailable(date) {
dmy = date.getDate() + "-" + (date.getMonth()+1) + "-" + date.getFullYear();
if ($.inArray(dmy, unavailableDates) == -1) {
return [true, ""];
} else {
return [false,"","Unavailable"];
}
}
var dp = $('#datepicker').datepicker({ beforeShowDay: unavailable });
function update_datepicker()
{
$.ajax({
type: "POST",url: "scripts/deals.php?val=05&city="+$('#city_combo').val(),
success: function (temp2)
{unavailableDates = [eval(temp2)];}
});
}
just add, $('#datepicker').datepicker( "destroy" ); 只需添加$('#datepicker')。datepicker(“ destroy”); Before you recreate it, hope this helps otehrs
在您重新创建它之前,希望对您有所帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.