我的ruby on rails应用程序上有一个引导日期选择器,但它仍然选择今天的日期作为默认值,如何阻止它?
的Javascript
<script type="text/javascript">
$(".datepicker").attr('readOnly', 'true').css("background-color","white");
$(document).ready(function(){
$('.datepicker').datepicker({
"setDate": new Date(-70),
yearRange : '-70:-19',
dateFormat: 'dd/mm/yy',
changeMonth: true,
changeYear: true,
autoclose: true});
});
</script>
如下所示,今天选出了30日游行。如果用户没有更改年份或月份,则初始视图中的行军日期将选择 &#34; 2018年3月和#34;
非常感谢任何帮助!
答案 0 :(得分:0)
首先,这不是一个bootstrap datePicker,这是jquery datePicker,请参阅下面的bootstrap datePicker,对于bootstrap datePicker你可以使用bootstrap datePicker gem,尝试将以下内容添加到todayHighlight: false
$(document).ready(function() {
var dateInput = $('input[name="date"]'); // Our date input has the name "date"
var container = $('.bootstrap-iso form').length > 0 ? $('.bootstrap-iso form').parent() : 'body';
dateInput.datepicker({
"setDate": new Date(-70),
yearRange : '-70:-19',
dateFormat: 'dd/mm/yy',
todayHighlight: false,
changeMonth: true,
changeYear: true,
autoclose: true
});
$('#date').datepicker('setStartDate'); // <-- SO DOES THIS
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.5/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.4/js/bootstrap-datepicker.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/css/tether.min.css" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.5/css/bootstrap.min.css" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.4/css/bootstrap-datepicker.min.css" rel="stylesheet"/>
<div class="bootstrap-iso">
<div class="container-fluid">
<div class="row">
<div class="col-md-6 col-sm-6 col-xs-12">
<form class="form-horizontal" method="post">
<div class="form-group ">
<div class="col-sm-10">
<input class="form-control" id="date" name="date" placeholder="MM/DD/YYYY" type="text" />
</div>
</div>
</form>
</div>
</div>
</div>
</div>
&#13;