我在我的代码中使用了一个jquery datepicker用于用户输入。但我有一个要求,我必须在我的jquery datepicker中的特定日期仅显示5天,不包括周末。请你协助,因为我是jquery的新手?
此致 MIRU
我已经从dat_eta获取了5天内隐藏变量中的数组。现在我需要知道如何在datepicker中启用这些天。
请找到以下代码。
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="JAVASCRIPT_CALENDAR_TESTING.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<link href="../Content/themes/jquery-ui.css" rel="stylesheet" />
<script src="../Scripts/jquery-1.8.2.js"></script>
<script src="../Scripts/jquery-ui-1.8.24.js"></script>
<script>
$(function() {
$("#datepicker").datepicker();
});
</script>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td>Request date:</td>
<td><input type="text" id="datepicker" /></td>
<%
int scm_date;
scm_date = (9 / 24 + 1);
DateTime dat_eta = DateTime.Now;
string result;
dat_eta = dat_eta.AddDays(scm_date);
result = dat_eta.ToString("MM:dd:yyyy");
string[] array = new string[6];
for (int i = 0; i <= 5; i++) {
if (i == 0) {} else {
dat_eta = dat_eta.AddDays(1);
}
result = dat_eta.ToString("MM:dd:yyyy");
array[i] = result;
}
hiddenvalue.Value = string.Join(",", array);
%>
<td><input type="hidden" id="hiddenvalue" name="hiddenvalue" runat="server" /></td>
</tr>
</table>
<script type="text/javascript">
</script>
</div>
</form>
</body>
</html>
答案 0 :(得分:0)
您可以使用beforeShowDay option。
/*
* let's assume your array is like the following one
*/
var datValues = ['03:11:2018','03:12:2018','03:13:2018'];
$("#datepicker").datepicker({
beforeShowDay: function(date) {
return [datValues.indexOf($.datepicker.formatDate('mm:dd:yy', date)) > -1];
}
});
&#13;
<link href="https://code.jquery.com/ui/1.8.24/themes/smoothness/jquery-ui.css" rel="stylesheet"/>
<script src="https://code.jquery.com/jquery-1.8.2.min.js"></script>
<script src="https://code.jquery.com/ui/1.8.24/jquery-ui.js"></script>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td>Request date:</td>
<td><input type="text" id="datepicker"/></td>
<td><input type="hidden" id="hiddenvalue" name="hiddenvalue" runat="server"/></td>
</tr>
</table>
</div>
</form>
&#13;