Bootstrap timepicker goes negative when clicking up and down arrow

六月ゝ 毕业季﹏ 提交于 2021-01-29 04:37:39

问题


In the input field of timepicker, initially I just need placeholder there and I decided to setdefaultTime as false:

<input type="text" class="timepicker" placeholder="Enter time">
<script>
$('.timepicker').timepicker({
    defaultTime:false
 });
</script>

But after setting default time to false, whenever I click up and down arrow for changing time the hour value goes negative. In the documenation I found nothing helpful for this issue. How do I get rid off that negative values ? Any help would be appreciated.


回答1:


I was going through same issue couple of weeks ago and I solve the issue by setting time to timepicker just after clicking input field:

$(document).on("click",".timepicker",function(){
    var d = new Date();
    var current_time = moment(d).format('hh:mm A'); // time format with moment.js
    $(this).timepicker('setTime', current_time); // setting timepicker to current time
    $(this).val(current_time); // setting input field to current time
});


来源:https://stackoverflow.com/questions/43024147/bootstrap-timepicker-goes-negative-when-clicking-up-and-down-arrow

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