由于这是不可能的,我想出解决方法:将函数作为参数传递给自定义 jQuery 函数。这是创建日期选择器的代码:
var onSelectFunction = function(dateValue){
$('#end_date.datepicker').datepicker("option", "minDate", dateValue);
}
options.onSelect = onSelectFunction;
$('#start_date.datepicker, #end_date.datepicker').attachCustomDatepicker(options);
这是我的自定义函数的预览:
$.fn.attachCustomDatepicker = function(options) {
var defaultOptions = {
someDefaultCustomParamsHere: ,
onSelect: null
}
var onSelectFunction = function(params){ return false; }
if (typeof options == 'object') {
options = $.extend(defaultOptions, options);
} else {
options = defaultOptions;
}
if(!options.onSelect){
options.onSelect = onSelectFunction;
}
$(this).datepicker( "destroy" );
$(this).datepicker({
onSelect: function (dateValue, inst) {
options.onSelect(dateValue);
}
}
}