我必须做数据报警器,它的工作方式是这样的:如果选定的月份有偶数天(30天),那么这个月的所有偶数天都会被阻塞来选择(2,4,6.)如果选定的月份有奇数的天数(31天),则数据报机中的所有奇数日都将被阻塞以进行选择(1,3,5.)等。
我的问题是,我不知道如何阻止偶数和奇数天,我只知道如何阻止整个月,但不知道任何一天特别.免责声明:我知道已经有一些东西,如如何阻止特定的日子,但没有任何与偶数或奇数天。
这是我的代码:
<link rel="stylesheet" href="jquery-ui.min.css">
<script src="external/jquery/jquery.js"></script>
<script src="jquery-ui.min.js"></script>
<script>
$(function() {
$( "#datepicker" ).datepicker({beforeShowDay: nationalDays});
});
function nationalDays(date){
var x = date.getMonth();
var r = x%2;
if(r == 0){
return [false];
}
else if(r == 1){
return [true];
}
}
</script>
</head>
<body>
<p>Date: <input type="text" id="datepicker"></p>
</body>发布于 2014-11-21 17:14:23
在beforeShowDay选项中,您可以检查是否应该启用日期,并将数组中的第一个项设置为true/false。True将启用该项,而false将禁用该项,如下所示:
$(function() {
$("#datepicker").datepicker({
defaultDate: new Date(),
beforeShowDay: function(date) {
var disabled = true, // date enabled by default
// get the number of days in current month
numOfDays = new Date(date.getFullYear(), date.getMonth() + 1, 0).getDate();
if (numOfDays % 2 == 0)
disabled = (date.getDate() % 2 != 0) // for even-days months, disable the even dates
else disabled = (date.getDate() % 2 == 0) //for odd - days months, disable the odd dates
return [disabled, ""]
}
});
});<link href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
<p>Date:
<input type="text" id="datepicker" />
</p>
https://stackoverflow.com/questions/27066350
复制相似问题