如何让一个 jquery 日期选择器输入与另一个输入的值集成?
我有一个带有 3 个输入字段的表单,使用 jQuery 的 DatePicker 插件。这些字段是#startdate、#enddate 和#raindate。我正在使用 DatePicker 的事件函数来让 #startdate 和 #enddate 一起工作,因此 #enddate 不能在 #startdate 之前。顺便说一句,这两个字段都是必需的。 #raindate 字段不是必需的。但是,如果用户想在此处添加日期,我希望它位于#enddate 中选择的日期之后。我该怎么做?这是我让开始日期和结束日期一起工作的代码:
function getDates() {
var dates = $("#startdate, #enddate" ).datepicker({
defaultDate: "+1d",
changeMonth: true,
numberOfMonths: 1,
onSelect: function( selectedDate ) {
var option = this.id == "startdate" ? "minDate" : "maxDate",
instance = $( this ).data( "datepicker" );
date = $.datepicker.parseDate(
instance.settings.dateFormat ||
$.datepicker._defaults.dateFormat,
selectedDate, instance.settings );
dates.not( this ).datepicker( "option", option, date );
}
});
}
有没有办法指定这样的东西?:
minDate: $(#enddate).val() + 1d
I have a form with 3 input fields that use jQuery's DatePicker plugin. The fields are #startdate, #enddate, and #raindate. I am using DatePicker's event function to get the #startdate and #enddate to work together so the #enddate cannot be before the #startdate. Both those fields are required, by the way. The #raindate field is not required. However, if the user wants to add a date here, I want it to be after the date selected in the #enddate. How do I do this? Here is the code I have for getting the startdate and enddate to work together:
function getDates() {
var dates = $("#startdate, #enddate" ).datepicker({
defaultDate: "+1d",
changeMonth: true,
numberOfMonths: 1,
onSelect: function( selectedDate ) {
var option = this.id == "startdate" ? "minDate" : "maxDate",
instance = $( this ).data( "datepicker" );
date = $.datepicker.parseDate(
instance.settings.dateFormat ||
$.datepicker._defaults.dateFormat,
selectedDate, instance.settings );
dates.not( this ).datepicker( "option", option, date );
}
});
}
Is there a way to specify something like this?:
minDate: $(#enddate).val() + 1d
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,有一个名为 minDate 的选项,它还支持更多选项。
要获取所有可用选项,请转到 -
http://jqueryui.com/demos/datepicker/
那里转到选项选项卡。
上述可以通过以下代码实现 -
Yes there is an option called minDate and it also supports a lot more options.
To get all available options go to -
http://jqueryui.com/demos/datepicker/
Over there go to options tab.
The above can be achieved by following code -