在Bootstrap Datetimepicker中禁用分钟选择

时间:2017-12-26 11:25:31

标签: javascript jquery twitter-bootstrap datetimepicker

我不想使用datetimepicker来显示舍入小时数并禁用分钟选择。所以用户只能选择几小时,比如02:00。但是我无法完成这个简单的任务。这是我的代码(在Laravel视图中):

$("#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: 60stepping:60minView: 1和其他人。 我仍然得到这个enter image description here

3 个答案:

答案 0 :(得分:1)

以下是您的一个示例,我认为它会对您有所帮助。

jsfiddle.net/tmk0293z/7 /

使用函数更改事件绑定并更改其他字段的另一个startdate。

谢谢, Nishit Zinzuvadiya

这是实际的代码 (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

 });

答案 1 :(得分:0)

答案 2 :(得分:0)

尝试使用步骤:60 而非步骤 请检查此链接:click here