javascript Bootstrap Datepicker - 设置 startView:'decade',但不是当前的十年
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15503325/
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
Bootstrap Datepicker - Set startView: 'decade', but not current decade
提问by jamiethepiper
Currently I have the startView showing the current decade, which is ok but I want to make the previous decade be the startView - not the current decade.
目前我有 startView 显示当前十年,这没问题,但我想让前十年成为 startView - 而不是当前十年。
this.dobDatePickerView = new DatePickerView({ el: this.$('[name="dob"]'), startView : 'decade', endDate : this.sandbox.dates().fwFormat('date'), value : this.sandbox.dates().subtract('years', 18).fwFormat('date') }).render();
I want to subtract 18 years from the decade view default selected year, so instead of '2013' being pre-selected it should default to 1995.
我想从十年视图默认选择的年份中减去 18 年,所以不是预先选择“2013”,而是默认为 1995。
采纳答案by Jason Sperske
This could work: (demo):
这可以工作:(演示):
<div class="input-append date" id="dp1" data-date="01-01-1990" data-date-format="dd-mm-yyyy" data-date-viewmode="years">
<input class="span2" size="16" type="text" readonly>
<span class="add-on"><i class="icon-calendar"></i></span>
</div>
<script>
$('#dp1').datepicker();
</script>
By separating the datepicker from the input and setting a default value on the picker but not the input, you can get something that will only populate a date once a date is selected but start at any value you please.
通过将日期选择器与输入分开并在选择器上设置默认值而不是输入,您可以获得一些东西,它只会在选择日期后填充日期,但可以从您喜欢的任何值开始。
回答by user2187338
https://github.com/eternicode/bootstrap-datepicker#setstartdate
https://github.com/eternicode/bootstrap-datepicker#setstartdate
perhaps try calling setStartDate() on the datePicker, when it is clicked/opened, and set the date ten years ago
也许尝试在 datePicker 上调用 setStartDate(),当它被点击/打开时,并设置十年前的日期