Question about jQuery DatePicker Plugin
I have a question reguards to the jQuery DatePicker Plugin.
I know there is something called AltField.
I have a date range function, which is just the demo codes.
The code is here
$(function() {
var dates = $( "#from, #to" ).datepicker({
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 3,
onSelect: function( selectedDate ) {
var option = this.id == "from" ? "minDate" : "maxDate",
instance = $( this ).data( "datepicker" ),
date = $.datepicker.parseDate(
instance.settings.dateFormat ||
$.datepicker._defaults.dateFormat,
selectedDate, instance.settings );
开发者_JS百科 dates.not( this ).datepicker( "option", option, date );
}
});
});
My question is how to apply two different AltField for each of the input field?
Thanks a lot.
I spent whole afternoon already and still get any clue...
altField
(note the lower-case "a", as you have used an upper-case "A" in your question) is just another option the datepicker
function takes in it's options object argument (just like defaultDate
and changeMonth
for example, as you're already using them). Therefore, you can add it in just like those (altField
is a property of the options object; it's value should be a selector string):
var dates = $( "#from, #to" ).datepicker({
altField: "#someOtherField",
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 3,
onSelect: function( selectedDate ) {
var option = this.id == "from" ? "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 );
}
});
The above example would use whatever matches the selector #someOtherField
as the altField
. This goes hand-in-hand with the altFormat
option, which allows you to specify the format of the value in the alternate field. For more information, just read the docs.
AltField allows you to update another text input with the datepicker value.
Add altField: '#actualDate',
to the init string, after numberOfMonths, before onSelect
Where #actualDate is the id of another text input
<input type="text" id="actualDate" />
精彩评论