将我的头撞在墙上一天,并在网上阅读了很多答案后,我终于想出了一个简单的方法,将日期值插入到日期输入控件中。
以下是解决方案。猜猜它也可以帮助别人
<input type="date" class="form-control arial no-radius" id="StartDate" onchange="dataClerk('set expiry date')"/>
function dataClerk(action) {
if (action == 'set expiry date') {
var date = new Date($('#StartDate').val());
var day = date.getDate();
var month = date.getMonth() + 1;
var year = date.getFullYear();
if (month < 10) {
month = '0' + month;
}
if (day < 10) {
day = '0' + day;
}
var show = (year + '-' + month + '-' + day);
$('#EndDate').val(show);
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="date" class="form-control arial no-radius" id="StartDate" onchange="dataClerk('set expiry date')" />
<input type="date" class="form-control arial no-radius" id="EndDate" disabled/>
function dataClerk(action) {
if (action == 'set expiry date') {
var date = new Date($('#StartDate').val());
var day = date.getDate();
var month = date.getMonth() + 1;
var year = date.getFullYear();
if (month < 10) {
month = '0' + month;
}
if (day < 10) {
day = '0' + day;
}
var show = (year + '-' + month + '-' + day);
$('#EndDate').val(show);
}
}