bootstrap date picker clear value

穿精又带淫゛_ 提交于 2019-12-12 06:52:33

问题


I have two dates, Start date and End date. I need to validate the the end date should not greater than the start date.

need to clear (previous start date value) the date value when ever we change the date.

  • case 1# [ First time] start date - 23-Nov-2013 End date - 24-Nov-2013

now i changed the start date as -25-Nov-2013, but end date enabled the the 24-Nov-2013 (start previous value) on wards instead of 26-Nov-203.

So, i need to clear the value when ever i change the date.


回答1:


Actually, what that 27/11/2013 represents is the current Date. Which will not get updated unless you write it on changeDate event.

So you have to do like

  1. Bind the start date, with changeDate event.
  2. Increment the selected date in start.
  3. Again set back the incremented date.
  4. Now update this to end Date using update method

    $('#end').datepicker('update', toDate);

Finally, you code will be like

$('#start').datepicker({}).on('changeDate', function (ev) {
    var toDate = ev.date;
    toDate.setDate(toDate.getDate() + 1);
    $('#end').datepicker('update', toDate);
});
$('#end').datepicker({});

JSFiddle



来源:https://stackoverflow.com/questions/20235758/bootstrap-date-picker-clear-value

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!