在更改选择框时更改 BootStrap Datepicker 的 startDate 和 endDate 参数 [英] Changing startDate and endDate params of BootStrap Datepicker on change of a select Box
本文介绍了在更改选择框时更改 BootStrap Datepicker 的 startDate 和 endDate 参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想做什么:
我正在尝试根据年份的当前值设置 startDate 和 endDate 参数.我认为当前我刚刚设置了 onLoad 参数,但是我需要知道是否有一种方法可以让我在某些事件上触发 startDate/endDate 参数的更新
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
代码如下:
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:
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];
}
小提琴:http://jsfiddle.net/fRzyL/1/
推荐答案
更改option
的值2013-2014和2015-2016like
<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>
把它改成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();
这篇关于在更改选择框时更改 BootStrap Datepicker 的 startDate 和 endDate 参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文