如何使用jQuery禁用日期选择器中的将来日期? [英] How to disable future dates in datepicker using jquery?
本文介绍了如何使用jQuery禁用日期选择器中的将来日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
日期选择器的将来日期未禁用.这是我的HTML中日期选择器的代码
Datepicker future dates not disable. Here is my code for datepicker in HTML
<div class="input-group input-append date" id="dp3" data-date="" data-date-format="mm-dd-yyyy">
<input class="form-control" style="width: 106px; height: 30px;" type="text" id="nodate" value="<?php echo date('m-j-Y');?>" readonly=""/>
<div class="input-group-addon add-on" style="width: 35px; height: 25px;"><i class="icon-calendar"></i></div>
 
<button type="button" class="btn btn-primary" onclick="window.location = '<?php echo base_url().'index.php/attendance/noRecordDate/';?>'+ $('#nodate').val()">Add Attendance</button>
</div>
这是我的剧本:
<script>
$(function() {
$( "#nodate" ).datepicker({ maxDate: new Date() });
});
</script>
推荐答案
$(document).ready(function () {
var dbDate = "2017-03-24";
var date2 = new Date(dbDate);
$( "#nodate" ).datepicker({
dateFormat: 'mm-dd-yy',
maxDate: new Date()
}).datepicker('setDate', date2);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<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>
<div class="input-group input-append date" id="dp3" data-date="" data-date-format="mm-dd-yyyy">
<input class="form-control" style="width: 106px; height: 30px;" type="text" id="nodate" value="" readonly=""/>
<div class="input-group-addon add-on" style="width: 35px; height: 25px;"><i class="icon-calendar"></i></div>
 
<button type="button" class="btn btn-primary" onclick="window.location = '<?php echo base_url().'index.php/attendance/noRecordDate/';?>'+ $('#nodate').val()">Add Attendance</button>
</div>
这篇关于如何使用jQuery禁用日期选择器中的将来日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文