jQuery 在日期选择器上禁用过去的日期
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15757918/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
disable past dates on datepicker
提问by Anna
How to disable past dates from the current date on a datetimepicker? I tried few posts for similar question but was unable to achieve it, Below is what I tried
如何在日期时间选择器上禁用当前日期的过去日期?我尝试了一些类似问题的帖子,但无法实现,以下是我尝试过的
<link href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.2.2/css/bootstrap-combined.min.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" media="screen"
href="http://tarruda.github.com/bootstrap-datetimepicker/assets/css/bootstrap-datetimepicker.min.css">
<script type="text/javascript"
src="http://cdnjs.cloudflare.com/ajax/libs/jquery/1.8.3/jquery.min.js">
</script>
<script type="text/javascript"
src="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.2.2/js/bootstrap.min.js">
</script>
<script type="text/javascript"
src="http://tarruda.github.com/bootstrap-datetimepicker/assets/js/bootstrap-datetimepicker.min.js">
</script>
<script type="text/javascript"
src="http://tarruda.github.com/bootstrap-datetimepicker/assets/js/bootstrap-datetimepicker.pt-BR.js">
</script>
<script type="text/javascript">
$(function() {
$('#datetimepicker2').datetimepicker({
language: 'en',
pick12HourFormat: true
});
});
</script>
<div id="datetimepicker2" class="input-append">
<input data-format="MM/dd/yyyy" type="text"/>
<span class="add-on">
<i data-date-icon="icon-calendar">
</i>
</span>
I also tried
我也试过
$("datetimepicker2").datepicker({ changeYear: true, dateFormat: 'dd/mm/yy', showOn: 'none', showButtonPanel: true, minDate:'0d' });
and
和
$("#datetimepicker2").datepicker({ minDate: 0 });
回答by Jay Mayu
Give zero to mindate
and it'll disabale past dates.
给零mindate
,它会禁用过去的日期。
$( "#datepicker" ).datepicker({ minDate: 0});
here is a Live fiddleworking example http://jsfiddle.net/mayooresan/ZL2Bc/
这是一个Live fiddle工作示例http://jsfiddle.net/mayooresan/ZL2Bc/
回答by Anna
Problem fixed :)
问题已解决:)
below is the working code
下面是工作代码
$(function(){
$('#datepicker').datepicker({
startDate: '-0m'
//endDate: '+2d'
}).on('changeDate', function(ev){
$('#sDate1').text($('#datepicker').data('date'));
$('#datepicker').datepicker('hide');
});
})
回答by Techie
回答by Annonymous programmer
try this,
尝试这个,
$( "#datepicker" ).datepicker({ minDate: new Date()});
Here, new Date() implies today's date....
在这里, new Date() 表示今天的日期....
回答by Rama Krishna
$(function () {
$("#date").datepicker({ minDate: 0 });
});
回答by VIPIN A ROY
This will work:
这将起作用:
var dateToday = new Date();
$(function () {
$("#date").datepicker({
minDate: dateToday
});
});
回答by Pabari Mohit
Try this,
尝试这个,
$("#datetimepicker2").datepicker({ startDate: "+0d" });
回答by pralhad bulange
var dateToday = new Date();
$('#datepicker').datepicker({
'startDate': dateToday
});
回答by salamflamo
this works for me,
这对我有用,
$('#datetimepicker2').datetimepicker({
startDate: new Date()
});
回答by Shahid Ahmed
<div class="input-group date" data-provide="datepicker" data-date-start-date="0d">
<input type="text" class="form-control" id="input_id" name="input_name" />
<div class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</div>
</div>