How check if jQuery datepicker is empty?

独自空忆成欢 提交于 2019-12-23 07:38:42

问题


I have a date picker empty, but I do not know how to check if is empty (not validated or not)


回答1:


You can check the value of the input using .val(), like this:

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:

if($("#fieldID").datepicker("getDate") === null) {
  alert("no date selected");
}



回答2:


I used something like this and it worked for me.

if($("#fieldID").val() == undefined) {
  alert("no date selected");
}


来源:https://stackoverflow.com/questions/4109913/how-check-if-jquery-datepicker-is-empty

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!