jQuery 在更改选择框时更改 BootStrap Datepicker 的 startDate 和 endDate 参数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19269813/
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
Changing startDate and endDate params of BootStrap Datepicker on change of a select Box
提问by Avinash
What I am trying to do :
我正在尝试做的事情:
I am trying to set the startDate and endDate params depending on the current value of year. I think that currenty what I have just sets the params onLoad, however I need to know if there is a way which can enable me to trigger the updation of startDate / endDate Params on some event
我正在尝试根据年份的当前值设置 startDate 和 endDate 参数。我认为当前我刚刚设置了 onLoad 参数,但是我需要知道是否有一种方法可以让我在某些事件上触发 startDate / endDate 参数的更新
Here is the code :
这是代码:
html :
html :
<select id="mySelect">
<option value="2012-2013">2012-2013</option>
<option value="2012-2013">2013-2014</option>
<option value="2012-2013">2015-2016</option>
</select>
<input type="text" id="myStartDate" placeholder="dd-mon-yyyy" data-date-format="dd-M-yyyy" readonly="readonly">
js :
js:
var myStartDt = $('#myStartDate')
.datepicker({
startDate: getStartDate(),
endDate: getEndDate()
}).on('changeDate', function (ev) {
myStartDt.hide();
}).data('datepicker');
function getStartDate() {
var f = $('#mySelect').val().split('-');
return '01/04/' + f[0];
}
function getEndDate() {
var f = $('#mySelect').val().split('-');
alert(f);
return '31/03/' + f[1];
}
fiddle : http://jsfiddle.net/fRzyL/1/
回答by ivkremer
I think you can simply use setStartDate
and setEndDate
methods: http://jsfiddle.net/ivkremer/fRzyL/21/
我认为你可以简单地使用setStartDate
和setEndDate
方法:http: //jsfiddle.net/ivkremer/fRzyL/21/
回答by Rohan Kumar
Change the values of option
2013-2014 and 2015-2016like
更改option
2013-2014 和 2015-2016的值,例如
<select id="mySelect">
<option value="2012-2013">2012-2013</option>
<option value="2013-2014">2013-2014</option>
<option value="2015-2016">2015-2016</option>
</select>
Change this to js,
将其更改为js,
var myStartDt;
function mydatepicker(){
myStartDt= $('#myStartDate')
.datepicker({
startDate: getStartDate(),
endDate: getEndDate()
}).on('changeDate', function (ev) {
myStartDt.hide();
}).data('datepicker');
}
$("#mySelect").on('change',function(){
// alert(this.value)
$('#myStartDate').datepicker("remove");
mydatepicker();//$('#id-element').datepicker("destroy");
});
mydatepicker();