1 回答

TA貢獻1850條經(jīng)驗 獲得超11個贊
不要
click
在復選框上使用事件,使用change
if ($(this).is('checked')) {
- 它的is(':checked')
不要在復選框處理程序中初始化日期選擇器,單獨初始化它們
不要重新初始化它們,
option
而是使用更改特定設置的方法
$(function() {
$("#startdate").datepicker({
dateFormat: "dd'.'mm'.'yy",
firstDay: 1,
showOtherMonths: true,
selectOtherMonths: true
})
$("#enddate").datepicker({
dateFormat: "dd'.'mm'.'yy",
firstDay: 1,
showOtherMonths: true,
selectOtherMonths: true
})
$("#weekday").change(function() {
if ($(this).is(':checked')) {
$("#startdate, #enddate").datepicker('option', 'beforeShowDay', $.datepicker.noWeekends)
} else {
$("#startdate, #enddate").datepicker('option', 'beforeShowDay', null)
}
})
})
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<link rel="stylesheet" href="/resources/demos/style.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>
<body>
<input type="checkbox" id="weekday" name="weekday" value="weekday">
<label for="weekday">Only during working days</label><br>
<p>Start Date: <br><input type="text" id="startdate" name="startdate"></p>
<p>End Date: <br><input type="text" id="enddate" name="enddate"></p>
<p>Quantity: <br><input type="text" id="quantity" name="quantity"><br></p>
<br>
<input type="submit" value="Calculate">
</body>
添加回答
舉報