Javascript 如何在 Bootstrap 时间选择器上设置默认时间
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26584649/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to set default time on Bootstrap timepicker
提问by iamspauljamez
How can I set default time instead of current time for this datetimepicker http://tarruda.github.io/bootstrap-datetimepicker/?
如何为此 datetimepicker http://tarruda.github.io/bootstrap-datetimepicker/设置默认时间而不是当前时间?
回答by Veve
You can set the default time via JavaScript :
您可以通过 JavaScript 设置默认时间:
$('mySelector').timepicker({defaultTime: '10:45 PM'});
Or directly via the value attribute of your timepicker :
或者直接通过 timepicker 的 value 属性:
<div class="bootstrap-timepicker">
<input id="timepicker" type="text" value="10:45 AM"/>
</div>
$('.myClass').timepicker({defaultTime: 'value'});
EDIT : was for the default timepicker of boostrap, my bad.
编辑:用于 boostrap 的默认时间选择器,我不好。
For your specific timepicker, it seems possible to set the datetime like this :
对于您的特定时间选择器,似乎可以像这样设置日期时间:
var picker = $('#datetimepicker').data('datetimepicker');
picker.setDate(myDate);
回答by successtar
From the documentation page..
从文档页面。.
setTime Set the time manually
setTime 手动设置时间
$('#timepicker').timepicker('setTime', '12:45 AM');
回答by Hiten Gal
I Think You Should try this. It work for me
我认为你应该试试这个。它对我有用
$('.time').timepicker({
minuteStep: 1,
defaultTime: null
});
回答by Arindam Dawn
For bootstrap timepicker this would work :
对于引导时间选择器,这将起作用:
$('selector').val("time");

