有人知道我如何将代码隐藏中的日期列表传递给日历吗?这样它就会突出显示列表中的日期。谢谢
<script>
$(function () {
$("#datepicker").datepicker();
});
</script>
<p>Date: <input type="text" id="datepicker" /></p>
存储在代码后面的日期列表:
DateTime start = new DateTime(2013, 02, 20);
DateTime end = new DateTime(2013, 01, 11);
var dates = new List<DateTime>();
for (var dt = start; dt <= end; dt = dt.AddDays(1))
{
dates.Add(dt);
}
最简单的解决方案是创建一个asp.net处理程序或一个将日期作为json对象返回的网页,并在日期选择器内的beforeShowDate函数中使用它:
下面是一个简单的实现:
var dates = []; //replace [] with ajax call to the page that returns the dates
$("#datepicker").datepicker({
dateFormat: "dd-mm-yyyy",
beforeShowDay: function (date) {
var available = $.inArray(date, dates) > -1;
if (available) {
return [1]; //return available date
}
else {
return [0]; //return not available
}
}
});
后面的代码看起来像这样。您必须添加System.Web.Extensions.dll作为引用才能使用JavaScriptSerializer
protected void Page_Load(object sender, EventArgs e)
{
DateTime start = new DateTime(2013, 02, 20);
DateTime end = new DateTime(2014, 01, 11);
var dates = new List<string>();
for (var dt = start; dt <= end; dt = dt.AddDays(1))
{
dates.Add(dt.ToString("dd-MM-yyyy"));
}
Response.ContentType = "text/javascript";
string json = new JavaScriptSerializer().Serialize(dates);
Response.Write(json);
Response.End();
}`