gpt4 book ai didi

javascript - jquery 日期时间选择器 null 允许的时间

转载 作者:行者123 更新时间:2023-11-29 23:24:03 25 4
gpt4 key购买 nike

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

在 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">

最佳答案

如果数组为空,您可以销毁日期时间选择器。在使用日期时间选择器之前,您可以在这两种情况下进行检查。

$(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">

关于javascript - jquery 日期时间选择器 null 允许的时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49795453/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com