检查 DatePicker 值是否为 null
Check if DatePicker value is null
我想检查 DatePicker
的值是否为空(== 框中没有日期)。
默认情况下,我的 DatePicker
的 Text
设置为 Select a date
,所以我无法使用 Text
属性 来检查.
虽然DatePicker
的默认文本是Select a date
,但是您可以使用Text
属性来检查Text.Length
。或者像这样检查 SelectedDate
属性:
if (datePicker.Text.Length == 0)
{
//Do your stuff
}
或:
if (datePicker.SelectedDate == null)
{
//Do your stuff
}
DatePicker class 具有 属性、SelectedDate,可让您获取或设置所选日期。如果选择了none,则表示其值为空。
if (datePicker.SelectedDate == null)
{
// Do what you have to do
}
to = $('#to');// hopefully you defined this yourself and the options
//I am writing coffeeScript here, below I will add pure JS
if to.datepicker('getDate') == null
//basically do your stuff here -
//using month_day_year_string (m_d_y_s) func to format a date object here and add 6 to the date's year so passed e.g. 2014 gives 2020.
return to.datepicker('option', 'minDate', getDate(this), to.datepicker('option', 'maxDate', m_d_y_s(getDate(this), 6)))
return// I have this on a call back so I am returning from the call back
在纯 JS 中,它只是
var to = $('#to');// hope you defined the options and datepicker
if (to.datepicker('getDate') === null) {
#do your stuff - I have an example code below as I needed this check in a callback
return to.datepicker('option', 'minDate', getDate(this), to.datepicker('option', 'maxDate', m_d_y_s(getDate(this), 6)));
}
return;// if on a call back e.g. onChange or onRender.
我想检查 DatePicker
的值是否为空(== 框中没有日期)。
默认情况下,我的 DatePicker
的 Text
设置为 Select a date
,所以我无法使用 Text
属性 来检查.
虽然DatePicker
的默认文本是Select a date
,但是您可以使用Text
属性来检查Text.Length
。或者像这样检查 SelectedDate
属性:
if (datePicker.Text.Length == 0)
{
//Do your stuff
}
或:
if (datePicker.SelectedDate == null)
{
//Do your stuff
}
DatePicker class 具有 属性、SelectedDate,可让您获取或设置所选日期。如果选择了none,则表示其值为空。
if (datePicker.SelectedDate == null)
{
// Do what you have to do
}
to = $('#to');// hopefully you defined this yourself and the options
//I am writing coffeeScript here, below I will add pure JS
if to.datepicker('getDate') == null
//basically do your stuff here -
//using month_day_year_string (m_d_y_s) func to format a date object here and add 6 to the date's year so passed e.g. 2014 gives 2020.
return to.datepicker('option', 'minDate', getDate(this), to.datepicker('option', 'maxDate', m_d_y_s(getDate(this), 6)))
return// I have this on a call back so I am returning from the call back
在纯 JS 中,它只是
var to = $('#to');// hope you defined the options and datepicker
if (to.datepicker('getDate') === null) {
#do your stuff - I have an example code below as I needed this check in a callback
return to.datepicker('option', 'minDate', getDate(this), to.datepicker('option', 'maxDate', m_d_y_s(getDate(this), 6)));
}
return;// if on a call back e.g. onChange or onRender.