如何检查 jQuery datepicker 是否为空?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4109913/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How check if jQuery datepicker is empty?
提问by rtacconi
I have a date picker empty, but I do not know how to check if is empty (not validated or not)
我的日期选择器为空,但我不知道如何检查是否为空(未验证或未验证)
回答by Nick Craver
You can check the value of the input using .val()
, like this:
您可以使用 来检查输入的值.val()
,如下所示:
if($("#fieldID").val() == "") {
alert("no date selected");
}
Or for inline datepickers and such as well, use getDate
which returns null
if there's nothing selected:
或者对于内联日期选择器等,如果没有选择任何内容,请使用getDate
which 返回null
:
if($("#fieldID").datepicker("getDate") === null) {
alert("no date selected");
}
回答by Nagaraja JB
I used something like this and it worked for me.
我使用了这样的东西,它对我有用。
if($("#fieldID").val() == undefined) {
alert("no date selected");
}