我想结合两个datepicker条件来显示日期
分开,他们工作。但是,当我将它们中的一个组合时,它们中只有一个。 我用我的代码做了一个小提琴。这里是。谢谢。
https://jsfiddle.net/y8ojanna/
HTML
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<div class="row">
<div class="col-md-2 col-sm-12 ">
<h3>Afhalen op:</h3>
</div>
<div class="col-md-4 col-sm-12 ">
<div id="date"></div>
<label>Geselecteerd:</label>
<input type="text" id="datefield" name="date" required data-readonly/>
</div>
</div>
JAVASCRIPT
var selected;
$(function() {
var date = new Date();
var dayNo = date.getDay();
var mindate = (7-dayNo);
$( "#date" ).datepicker({
dateFormat: 'yy-mm-dd', firstDay: 1,minDate: mindate
});
$('#date').datepicker({beforeShowDay: function(date){
return [date.getDay() != 1 & date.getDay() != 2 & date.getDay() != 3 & date.getDay() != 5 & date.getDay() != 0, ''];
}});
$('#date').on("change",function(){
selected = $(this).val();
document.getElementById('datefield').value = selected;
});
});
答案 0 :(得分:1)
以下代码将执行两项操作:
var dateToday = new Date();
$('#visit').datepicker({
beforeShowDay: checkAvailable,
minDate: '+1w'
});
function checkAvailable(date) {
var day = date.getDay();
return [(day == 4 || day == 5)];
}
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js"></script>
<link href="https://davidwalsh.name/demo/jquery-ui-css/custom-theme/jquery-ui-1.7.2.custom.css" rel="stylesheet"/>
<input type='text' id='visit' />
我希望这就是你要找的东西:)