2 回答
TA贡献1798条经验 获得超7个赞
您可以在加载后通过任何方法设置日期,否则在加载时不会触发更改事件。
$(document).ready(
function() {
$('#sandbox-container input').datepicker({
format: "dd/mm/yyyy",
language: "sv",
weekStart: 1,
todayBtn: true,
clearBtn: true,
daysOfWeekHighlighted: "0,6",
calendarWeeks: true,
autoclose: true,
todayHighlight: true
}).on('changeDate', checkDate);
}
)
function checkDate() {
console.log('change');
var from = $('#sandbox-container input').val();
var validDate = new Date(from);
var checkDate = Date.now();
checkDate = addDays(checkDate, 30);
if (checkDate >= validDate) {
//XSP.openDialog("#{id:dlgLCardValidDate}")
}
}
function addDays(date, days) {
var result = new Date(date);
result.setDate(result.getDate() + days);
return result;
}
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js"></script>
<link id="bs-css" href="https://netdna.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" rel="stylesheet">
<link id="bsdp-css" href="https://unpkg.com/bootstrap-datepicker@1.9.0/dist/css/bootstrap-datepicker3.min.css" rel="stylesheet">
<script src="https://unpkg.com/bootstrap-datepicker@1.9.0/dist/js/bootstrap-datepicker.min.js"></script>
<script src="https://unpkg.com/bootstrap-datepicker@1.9.0/dist/locales/bootstrap-datepicker.sv.min.js" charset="UTF-8"></script>
<div class="span5 col-md-5" id="sandbox-container"><input type="text" value="10/10/2019"></div>
添加回答
举报