bootstrap-datepicker setDaysOfWeekDisabled方法设置星期几不能选择,比如设置星期六星期天不能选择,通过setDatesDisabled方法也可以实现设置星期六星期天不能选择,但是需要自己去计算那天是星期六星期天,而setDaysOfWeekDisabled则通过传入0-6数字进行快速简单的设置。其中数字6表示星期六0表示星期天。
//初始化
var ops = {
multidate: true,//同时可以选中多个日期
todayHighlight: true, //设置当天日期高亮
language: 'zh-CN', //语言
autoclose: true, //选择后自动关闭
clearBtn: true,//清除按钮
format: "yyyy-mm-dd",//日期格式
};
$("#itxst").datepicker(ops);
function doAction() {
//通过数组设置星期六星期天不能选择
//$('#itxst').datepicker('setDaysOfWeekDisabled', [6,0]);
//通过字符串设置星期六星期天不能选择
$('#itxst').datepicker('setDaysOfWeekDisabled', '6,0');
}
copy
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>bootstrap-datepicker setDaysOfWeekDisabled方法例子</title> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no, minimal-ui"> <script src="https://www.itxst.com/package/jquery-3.5.1/jquery.min.js"></script> <script src="https://www.itxst.com/package/bootstrap-4.5.0/js/bootstrap.min.js"></script> <link href="https://www.itxst.com/package/bootstrap-4.5.0/css/bootstrap.css" rel="stylesheet"> <script src="https://www.itxst.com/package/bootstrap-datepicker-1.9.0/js/bootstrap-datepicker.min.js"></script> <script src="https://www.itxst.com/package/bootstrap-datepicker-1.9.0/locales/bootstrap-datepicker.zh-CN.min.js"></script> <link href="https://www.itxst.com/package/bootstrap-datepicker-1.9.0/css/bootstrap-datepicker.min.css" rel="stylesheet"> </head> <body style="padding:10px;"> <div class="container "> <input type="text" id="itxst" placeholder="选择日期" class="form-control" autocomplete="off"> <button type="button" class="btn btn-primary" onclick=" $('#itxst').datepicker('show')">setDaysOfWeekDisabled</button> </div> <script> //初始化 var ops = { multidate: true,//同时可以选中多个日期 todayHighlight: true, //设置当天日期高亮 language: 'zh-CN', //语言 autoclose: true, //选择后自动关闭 clearBtn: true,//清除按钮 format: "yyyy-mm-dd",//日期格式 }; $("#itxst").datepicker(ops); function doAction() { //通过数组设置星期六星期天不能选择 //$('#itxst').datepicker('setDaysOfWeekDisabled', [6,0]); //通过字符串设置星期六星期天不能选择 $('#itxst').datepicker('setDaysOfWeekDisabled', '6,0'); } doAction(); </script> </body> </html>
copy