在jquery UI datepicker范围内使用altFormat和altField [英] Using altFormat and altField in jquery UI datepicker range
问题描述
我正在尝试将从和到的日期范围添加到我的数据库。我使用altFormat和altField来捕获数据库格式的日期(yy-mm-dd),同时在UI中使用Datepicker jquery UI组件显示正常的日期格式。
I am trying to get range of dates "from" and "to" to add it to my DB. I use altFormat and altField to capture the date in DB format (yy-mm-dd) while displaying normal date format in the UI using Datepicker jquery UI component.
我的问题是:如何在Datepicker UI范围中使用它。在哪里可以为我的日期和时间指定altField?
My question is: How do I use this in the Datepicker UI range. Where can I specify the altField for my from and to datepickers?
http://jqueryui.com/demos/datepicker/#date-range
我的代码:
var dates = $( "#hotel_display_checkin_date, #hotel_display_checkout_date" ).datepicker({
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 1,
altFormat: "yy-mm-dd",
altField: "#hotel_checkin_date",
onSelect: function( selectedDate ) {
var option1 = this.id == "hotel_display_checkin_date" ? "minDate" : "maxDate",
instance = $( this ).data( "datepicker" ),
date = $.datepicker.parseDate(
instance.settings.dateFormat ||
$.datepicker._defaults.dateFormat,
selectedDate, instance.settings ),
options = {option1: date}
dates.not( this ).datepicker( "option", options );
}
});
我尝试将altField选项添加到options = {option1:date},但不起作用
I tried adding the altField option to options = {option1: date}, but that does not work
推荐答案
您的主要问题是您尝试使用相同的 altField
的入住和退房日期:
Your main problem is that you're trying to use the same altField
for both the check-in and check-out dates:
altField: '#hotel_checkin_date'
如果您单独绑定它们:
var opts = {
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 1,
altFormat: "yy-mm-dd"
onSelect: function(selectedDate) { ... }
};
$('#hotel_display_checkin_date').datepicker(
$.extend({
altField: '#hotel_checkin_date'
}, opts)
);
$('#hotel_display_checkout_date').datepicker(
$.extend({
altField: '#hotel_checkout_date'
}, opts)
);
,以便您可以指定单独的 altField
应该更好的工作。
so that you can specify separate altField
s then things should work better.
演示: http:/ /jsfiddle.net/ambiguous/bJ8bh/1/
这篇关于在jquery UI datepicker范围内使用altFormat和altField的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!