Jquery datepicker 不可用的日期
Jquery datepicker unavaialble dates
Html
<p>Date: <input id="datepicker" type="text"></p>
<div id="DesignIdUnavialble" style="display:none;">"17-2-2015","28-2-2015","01-1-1970","24-3-2015","25-2-2015","25-2-2015","26-2-2015","27-2-2015","21-3-2015"</div>
Javascript这里
var unavilabledates = $('#DesignIdUnavialble').html();
var availableDates = [unavilabledates];
//console.log(availableDates);
function available(date) {
dmy = date.getDate() + "-" + (date.getMonth()+1) + "-" + date.getFullYear();
if ($.inArray(dmy, availableDates) !== -1) {
return [false, "","Available"];
} else {
return [true,"","unAvailable"];
}
}
//$( "#datepicker" ).datepicker();
$('#datepicker').datepicker({
beforeShowDay: available,
dateFormat: "dd-mm-yy",
onSelect: function (date) {
}
});
我想隐藏不可用的日期,但我做不到..
当我执行此
var availableDates = ["17-2-2015","28-2-2015","01-1-1970","24-3-2015","25-2-2015","25-2-2015","26-2-2015","27-2-2015","21-3-2015"];
它的工作 properly.while 我正在使用这个
var unavilabledates = $('#DesignIdUnavialble').html();
var availableDates = [unavilabledates];
它不工作..我该如何解决这个问题?
你需要一个数组来表示不可用的脚本,但你所做的是将整个 html-string 放入一个数组中,因此该数组只包含 1 个字符串
试试看:
var unavilabledates = $('#DesignIdUnavialble').html();
var availableDates =[];
$(unavilabledates.split(",")).each(function(i, el){console.log(el);availableDates[i] = el.substring(1, el.length-1)});
编辑:更改代码
这一行:
console.log(availableDates)
输出这个:
[""17-2-2015","28-2-2015","01-1-1970","24-3-2015","2…","25-2-2015","26-2-2015","27-2-2015","21-3-2015""]
显然它不是数组。
这似乎有效:
console.log(unavilabledates.split(',').map(function(d){return d.replace(/"/g,'')}));
Html
<p>Date: <input id="datepicker" type="text"></p>
<div id="DesignIdUnavialble" style="display:none;">"17-2-2015","28-2-2015","01-1-1970","24-3-2015","25-2-2015","25-2-2015","26-2-2015","27-2-2015","21-3-2015"</div>
Javascript这里
var unavilabledates = $('#DesignIdUnavialble').html();
var availableDates = [unavilabledates];
//console.log(availableDates);
function available(date) {
dmy = date.getDate() + "-" + (date.getMonth()+1) + "-" + date.getFullYear();
if ($.inArray(dmy, availableDates) !== -1) {
return [false, "","Available"];
} else {
return [true,"","unAvailable"];
}
}
//$( "#datepicker" ).datepicker();
$('#datepicker').datepicker({
beforeShowDay: available,
dateFormat: "dd-mm-yy",
onSelect: function (date) {
}
});
我想隐藏不可用的日期,但我做不到..
当我执行此
var availableDates = ["17-2-2015","28-2-2015","01-1-1970","24-3-2015","25-2-2015","25-2-2015","26-2-2015","27-2-2015","21-3-2015"];
它的工作 properly.while 我正在使用这个
var unavilabledates = $('#DesignIdUnavialble').html();
var availableDates = [unavilabledates];
它不工作..我该如何解决这个问题?
你需要一个数组来表示不可用的脚本,但你所做的是将整个 html-string 放入一个数组中,因此该数组只包含 1 个字符串 试试看:
var unavilabledates = $('#DesignIdUnavialble').html();
var availableDates =[];
$(unavilabledates.split(",")).each(function(i, el){console.log(el);availableDates[i] = el.substring(1, el.length-1)});
编辑:更改代码
这一行:
console.log(availableDates)
输出这个:
[""17-2-2015","28-2-2015","01-1-1970","24-3-2015","2…","25-2-2015","26-2-2015","27-2-2015","21-3-2015""]
显然它不是数组。
这似乎有效:
console.log(unavilabledates.split(',').map(function(d){return d.replace(/"/g,'')}));