Javascript 输入日期阻止所有字段,解锁选定字段
我想屏蔽几乎所有的复选框,我只希望每周有2天和4天可用。有人知道怎么做吗 谢谢你的帮助 目前有以下代码:Javascript 输入日期阻止所有字段,解锁选定字段,javascript,html,html5-input-date,Javascript,Html,Html5 Input Date,我想屏蔽几乎所有的复选框,我只希望每周有2天和4天可用。有人知道怎么做吗 谢谢你的帮助 目前有以下代码: <input class="unstyled" type="date" id="datapicker"> const date = new Date(); currentDate = date.toISOString().slice(0,10); document.getElementById('datapicker').value = currentDate; documen
<input class="unstyled" type="date" id="datapicker">
const date = new Date();
currentDate = date.toISOString().slice(0,10);
document.getElementById('datapicker').value = currentDate;
document.getElementById('datapicker').min = currentDate;
const date=新日期();
currentDate=date.toISOString().slice(0,10);
document.getElementById('datapicker')。值=当前日期;
document.getElementById('datapicker')。min=currentDate;
有一篇关于这个问题的文章:。请看“不能消除天数,但这里有一个建议的解决方法”一节。您不能仅使用标记来限制特定日期,但作者建议以下解决方法:
var date = document.querySelector('[type=date]');
function noMondays(e){
var day = new Date( e.target.value ).getUTCDay();
// Days in JS range from 0-6 where 0 is Sunday and 6 is Saturday
if( day == 1 ){
e.target.setCustomValidity('OH NOES! We hate Mondays! Please pick any day but Monday.');
} else {
e.target.setCustomValidity('');
}
}
date.addEventListener('input',noMondays);
也有步骤参数,但它只允许您限制两天之间的部分间隙(例如,每两天):
我希望下面的代码能帮助您
$(function() {
$("#datapicker").datepicker(
{ beforeShowDay: function(day) {
var day = day.getDay();
if (day == 2 || day == 4) {
return [true];
} else {
return [false];
}
}
});
});
你能提供示例代码吗?在Stackoverflow上,希望您至少尝试编写您的解决方案。我更新了问题,而他不会带来任何东西
$(function() {
$("#datapicker").datepicker(
{ beforeShowDay: function(day) {
var day = day.getDay();
if (day == 2 || day == 4) {
return [true];
} else {
return [false];
}
}
});
});