如果有人有兴趣知道我是如何为此创建插件的,请按照下面的代码进行操作。最后我不得不使用隐藏字段,但事实证明这是我能找到成功使用日历的唯一方法。
HTML
<select id="day"><option>Day</option></select>
<select id="month"><option>Month</option></select>
<select id="year"><option>Year</option></select>
<input type="hidden" id="date-selector">
JavaScript
$.fn.showCalendar = function(options){
var defaults ={
selector : "#date-selector",
calendarIcon : "./images/icons/calendar.gif",
numberOfSelectableDays : "+60D",
dateFormat: "dd/mm/yy",
numberOfMonths : 3,
daySelector : "#day",
monthSelector : "#month",
yearSelector : "#year"
}
var $this = $(this);
var params = $.extend({},defaults, options);
var getDateFromDropDowns = function(){
var dateOnDropDowns = new Date($(params.daySelector).val(),$(params.monthSelector).val(),$(params.yearSelector).val());
return dateOnDropDowns;
}
return $this.each(function(){
$this.datepicker({
showOn: "button",
buttonImage: params.calendarIcon,
minDate: 0,
maxDate: params.numberOfSelectableDays,
dateFormat: params.dateFormat,
buttonImageOnly: true,
numberOfMonths: params.numberOfMonths,
setDate : getDateFromDropDowns,
onClose: function(dateText, inst) {
$(params.yearSelector).val(dateText.split('/')[2]);
$(params.daySelector).val(dateText.split('/')[0]);
$(params.monthSelector).val(dateText.split('/')[1]);
}
});
});
},