2

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

在 Jquery datetimepicker setting allowed time null set as example shows here which should be 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">

4

1 回答 1

1

如果数组为空,您可以销毁日期时间选择器。在这两种情况下,您都可以在 bing 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">

于 2018-11-21T12:34:29.797 回答