jquery - 需要在日期选择器联系表 7 中禁用假期和日期
问题描述
我看到了许多解决方案,但无法在我的联系表格 7 上禁用周日周一和节假日。尝试使用此解决方案并将其 id 放置在函数和页脚文件中,但它仍然显示。代码是
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script>
jQuery("#datepicker").datepicker({
beforeShowDay: function (date) {
return [date.getDay() == 2 || date.getDay() == 3 || date.getDay() == 4 ||
date.getDay() == 5 || date.getDay() == 6, ""]
}
});
</script>
<label> <span style="color: #000080;"><strong>Your Appointment Date</strong></span>(required)
[date* date-163 id:datepicker]</label>
解决方案
你可以用这个替换你的脚本 .. 并将你的假期列表附加到 removeDays 变量中。
function disabledays(date) {
var ymd = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
//if u have to disable a list of day
var removeDays = ["2013-6-11","2013-6-31" ];
if ($.inArray(ymd, removeDays) >= 0) {
return [false];
} else {
//Show accept sundays
var day = date.getDay();
return [(day == 1 || day == 2 || day == 3 || day == 4 ||day == 5 ||day == 6 )];
}
}
$(function () {
$('#datepicker').datepicker({
beforeShowDay: disabledays
});
});
如果仍然无法正常工作,请分享您的控制台错误。
推荐阅读
- amazon-web-services - 分配标签后删除 S3 对象
- android - Android studio .h 文件找不到系统存储库
- json - 无法从 csv 文件的特定列解析特定值
- merge - 如何在 R 中执行 VLOOKUP?
- docker - Spring Cloud Dataflow 的 docker-compose up 出错 - “DATAFLOW_VERSION 未设置!”
- r - 在 R 中 install.packages() 时选择 CRAN 镜像的目的?
- javascript - 通过检查二维数组合并对象内的键
- python - 我无法通过 json 响应(网络抓取)获得想要的参数
- schematron - 使用 Schematron 验证 XML
- php - amp-mustache 不显示成功/错误消息