我一直在努力让 bootstrap-datepicker 在我的 rails 应用程序中工作。任何帮助,将不胜感激。谢谢!!
Rails -v: 3.2.12 jquery-rails: 3.0.4, 3.0.2, ....
这是我的html文件中的js:
<link href="/assets/datepicker.css?body=1" media="all" rel="stylesheet" type="text/css" />
<script src="/assets/jquery.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery_ujs.js?body=1" type="text/javascript"></script>
<script src="/assets/bootstrap-transition.js?body=1" type="text/javascript"></script>
<script src="/assets/bootstrap-affix.js?body=1" type="text/javascript"></script>
<script src="/assets/bootstrap-alert.js?body=1" type="text/javascript"></script>
<script src="/assets/bootstrap-button.js?body=1" type="text/javascript"></script>
<script src="/assets/bootstrap-carousel.js?body=1" type="text/javascript"></script>
<script src="/assets/bootstrap-collapse.js?body=1" type="text/javascript"></script>
<script src="/assets/bootstrap-dropdown.js?body=1" type="text/javascript"></script>
<script src="/assets/bootstrap-modal.js?body=1" type="text/javascript"></script>
<script src="/assets/bootstrap-scrollspy.js?body=1" type="text/javascript"></script>
<script src="/assets/bootstrap-tab.js?body=1" type="text/javascript"></script>
<script src="/assets/bootstrap-tooltip.js?body=1" type="text/javascript"></script>
<script src="/assets/bootstrap-popover.js?body=1" type="text/javascript"></script>
<script src="/assets/bootstrap-typeahead.js?body=1" type="text/javascript"></script>
<script src="/assets/bootstrap.js?body=1" type="text/javascript"></script>
<script src="/assets/bootstrap-datepicker.js?body=1" type="text/javascript"></script>
<script src="/assets/application.js?body=1" type="text/javascript"></script>
html片段:
<div class="control-group">
<label class="control-label" for="vps_eta_date">Estimated arrival date</label>
<div class="controls">
<div class="input-append date" id="dp3" data-date-format="dd-mm-yyyy">
<input class="span2" size="16" id="vps_eta_date" name="vps[eta_date]" type="text" value="12-02-2013" readonly>
<span class="add-on"><i class="icon-th"></i></span>
</div>
</div>
</div>
index.html 文件还包括从示例 ( http://vitalets.github.io/bootstrap-datepicker/ ) 复制的以下脚本:
<script>
$(function(){
window.prettyPrint && prettyPrint();
$('#dp1').datepicker({
format: 'mm-dd-yyyy',
todayBtn: 'linked'
});
$('#dp2').datepicker();
$('#btn2').click(function(e){
e.stopPropagation();
$('#dp2').datepicker('update', '03/17/12');
});
$('#dp3').datepicker();
var startDate = new Date(2012,1,20);
var endDate = new Date(2012,1,25);
$('#dp4').datepicker()
.on('changeDate', function(ev){
if (ev.date.valueOf() > endDate.valueOf()){
$('#alert').show().find('strong').text('The start date can not be greater then the end date');
} else {
$('#alert').hide();
startDate = new Date(ev.date);
$('#startDate').text($('#dp4').data('date'));
}
$('#dp4').datepicker('hide');
});
$('#dp5').datepicker()
.on('changeDate', function(ev){
if (ev.date.valueOf() < startDate.valueOf()){
$('#alert').show().find('strong').text('The end date can not be less then the start date');
} else {
$('#alert').hide();
endDate = new Date(ev.date);
$('#endDate').text($('#dp5').data('date'));
}
$('#dp5').datepicker('hide');
});
//inline
$('#dp6').datepicker({
todayBtn: 'linked'
});
$('#btn6').click(function(){
$('#dp6').datepicker('update', '15-05-1984');
});
$('#btn7').click(function(){
$('#dp6').data('datepicker').date = null;
$('#dp6').find('.active').removeClass('active');
});
});
</script>