问题
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