问题描述
我正在使用引导日期戳和线高图。
我希望日期戳记日期在图表缩放时进行更新。一旦该事件触发,我更新datepicker的值。值更新正常,但是当日历被点击时,弹出式日历上的日期仍然是旧的日期。
这是我的datepicker:
< div class =input-append date pull-rightid =dpStartDatedata-date =@ DateTime.Now.AddMonths(-1 ).ToString(dd / MM / yyyy)data-date-format =dd / mm / yyyy>
< input class =span2id =startDateTextsize =16type =textvalue =@ DateTime.Now.AddMonths(-1).ToString(dd / MM / yyyy )readonly =>
< span class =add-on>< i class =icon-th>< / i>< / span>
< / div>
我已尝试使用以下代码更新值:
$('#dpStartDate')。attr('data-date',startDate);
$('#startDateText')。attr('value',startDate);
更新日期不错,但不设置日历。
我还尝试触发onChange事件,它也更新日期,但不更新日历:
$('#dpStartDate')。trigger('changeDate',startDate);
$('#dpStartDate')。datepicker()
.on('show',function(ev){
ev.stopPropagation();
} )
.on('changeDate',function(ev,date){
var startDate = new Date();
if(date!= undefined){
startDate = date ;
$('#dpStartDate')。attr('data-date',startDate);
$('#startDateText')。attr('value',startDate);
}
else {
startDate = ev.date;
$('#dpStartDate')。attr(startDate.getDate()+'/'+(startDate.getMonth()+ 1)+ '/'+(startDate.getFullYear());
$('#startDateText')。attr(startDate.getDate()+'/'+(startDate.getMonth()+ 1)+'/'+ startDate .getFullYear());
}
$('#dpStartDate')。datepicker('hide');
ev.stopPropagation();
});有没有人知道是否可以更新这样的日历? $ b $(
b
谢谢
这适用于我
$(。datepicker)。datepicker(update,new Date());
I am using bootstrap datepicker along with a line highchart.
I want the datepicker date to update when the chart is zoomed. Once that event triggers I update the values of the datepicker. The values update fine but when the calendar is clicked, the date on the popup calendar is still the old date.
Here is my datepicker:
<div class="input-append date pull-right" id="dpStartDate" data-date="@DateTime.Now.AddMonths(-1).ToString("dd/MM/yyyy")" data-date-format="dd/mm/yyyy">
<input class="span2" id="startDateText" size="16" type="text" value="@DateTime.Now.AddMonths(-1).ToString("dd/MM/yyyy")" readonly="">
<span class="add-on"><i class="icon-th"></i></span>
</div>
I have tried just updating the values using this code:
$('#dpStartDate').attr('data-date', startDate);
$('#startDateText').attr('value', startDate);
which updates the dates fine but doesn't set the calendar.
I've also tried triggering the onChange event, which also updates the dates but not the calendar:
$('#dpStartDate').trigger('changeDate', startDate);
$('#dpStartDate').datepicker()
.on('show', function (ev) {
ev.stopPropagation();
})
.on('changeDate', function (ev, date) {
var startDate = new Date();
if (date != undefined) {
startDate = date;
$('#dpStartDate').attr('data-date', startDate);
$('#startDateText').attr('value', startDate);
}
else {
startDate = ev.date;
$('#dpStartDate').attr(startDate.getDate() + '/' + (startDate.getMonth() + 1) + '/' + startDate.getFullYear());
$('#startDateText').attr(startDate.getDate() + '/' + (startDate.getMonth() + 1) + '/' + startDate.getFullYear());
}
$('#dpStartDate').datepicker('hide');
ev.stopPropagation();
});
Does anyone know if it's even possible to update the calendar like that?
Thanks
This works for me
$(".datepicker").datepicker("update", new Date());
这篇关于如何动态设置bootstrap-datepicker的日期值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!