jquery datetime picker null允许的时间

时间:2018-04-12 11:32:32

标签: javascript jquery datetime timepicker jquerydatetimepicker

我有应用程序,其中有时间动态绑定,其中场景可能允许时间为空,

在Jquery中,datetimepicker设置允许时间null设置为此处显示的示例,该值应为null

如何设置空值时间?



$(document).ready(function(){
  try{ $('.DATETIMEFIELD').datetimepicker({
      value:'', 
      datepicker:false, 
      format:'h:i A', 
      formatTime: 'h:i A', 
      step:30 ,
      allowTimes: [], 
   }); 
   }
   catch(e){
       console.log(e);
   };
});

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery-datetimepicker/2.5.20/jquery.datetimepicker.css" /> 
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-datetimepicker/2.5.20/jquery.datetimepicker.full.js" id="_carbonads_js" defer></script>

<input type="text" class="DATETIMEFIELD">
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:1)

如果array为null,则可以销毁日期时间选择器。在这两种情况下,您都可以在查询datetimepicker之前进行检查。

$(document).ready(function(){
var timedata1=[32, 33, 12, 40]
var timedata2=[]
  try{ 
  $('.DATETIMEFIELD').datetimepicker({
      value:'', 
      datepicker:false, 
      format:'h:i A', 
      formatTime: 'h:i A', 
      step:30 ,
      allowTimes:timedata1, 
   }); 
   
   if(timedata2.length==0 || timedata2==null){
      $(".DATETIMEFIELD1").datepicker("destroy");      
   }else{
    $('.DATETIMEFIELD1').datetimepicker({
      value:'', 
      datepicker:false, 
      format:'h:i A', 
      formatTime: 'h:i A', 
      step:30 ,
      allowTimes:timedata1, 
   }); 
   }
   }
   catch(e){
       console.log(e);
   };
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery-datetimepicker/2.5.20/jquery.datetimepicker.css" /> 
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-datetimepicker/2.5.20/jquery.datetimepicker.full.js" id="_carbonads_js" defer></script>

While Having Value
<input type="text" class="DATETIMEFIELD">
While not Having Value
<input type="text" class="DATETIMEFIELD1">