问题描述
我不会设置datetimepicker仅显示四舍五入的小时数并禁用分钟选择.因此,用户只能选择小时,例如02:00.但是我无法完成这个简单的任务.这是我的代码(在Laravel视图中):
I wan't datetimepicker to show only rounded hours and disable minutes selection. So user will be able to pick only hours, like 02:00. However I can't achieve this simple task. Here is my code (in a Laravel view):
$("#date_from").datetimepicker({
format: 'yyyy-mm-dd hh:00',
startDate: "{{date('Y-m-d')}}",
minuteStepping: 60,
autoclose: true }).on('hide', function(e) {
$("#date_to").datetimepicker(
"setStartDate", new Date($('#date_from').val())
)....
我尝试了 steps:60
, stepping:60
, minView:1
等.仍然我得到这个
I've tried steps: 60
, stepping:60
, minView: 1
and others.Still I'm getting this
推荐答案
以下是您的一个示例,我认为它将为您提供帮助.
Here is one example for you, i think it will help you.
jsfiddle.net/tmk0293z/7/
jsfiddle.net/tmk0293z/7/
通过函数绑定了changeate事件,并更改了其他字段的另一个开始日期.
There is changedate event bind with a function and changes the another startdate of other field.
谢谢,尼希特·津祖瓦迪亚(Nishit Zinzuvadiya)
Thanks,Nishit Zinzuvadiya
这是实际的代码(HTML):
Here is the actual code(HTML):
<div class="input-append date form_datetime" id="first">
<input type="text" value="" readonly>
<span class="add-on"><i class="icon-th"></i></span>
</div>
<div class="input-append date form_datetime" id="second">
<input type="text" value="" readonly>
<span class="add-on"><i class="icon-th"></i></span>
</div>
<span id="selected"></span>
JS:
$(".form_datetime").datetimepicker({
format: "dd MM yyyy - hh:ii",
minView:1,
autoclose:true
});
$("#first").datetimepicker().on("changeDate", function(e){
var first = new Date(e.date.setMinutes(0));
first.setHours(first.getHours()+first.getTimezoneOffset()/60); //timezone correction
$("#second").datetimepicker('setStartDate', first);
//other = $("#first").find("input").val();
//$("#second").datetimepicker('setStartDate', other); //works also
});
这篇关于在Bootstrap Datetimepicker中禁用分钟选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!