我正在尝试将新方法注入jQuery。基本上,我从jQuery Min文件中加载了一个datepicker。现在,我想在加载此datePicker时注入一个新的方法DateComperiance()。
$("#ID").datepicker({
onClose: removeAria,
showOn: 'button',
buttonImageOnly: false,
})
dateCompliance();// this is what I want to load along with datepicker everytime it loads. this is coming from another datecode.js file.
谢谢您的提示!
创建一个基本的jQuery插件,并在要初始化datepicker调用自定义插件时,同时进行datepicker初始化和自定义函数调用。
$.fn.customDatepicker = function(option) {
// within plugin code this refers to jQuery object of the element
// initialize datepicker with the options
this.datepicker(option);
// call the function
dateCompliance();
// return jQuery object reference for chaining
return this;
};
并使用以下代码初始化datepicker。
$("#ID").customDatepicker({
onClose: removeAria,
showOn: 'button',
buttonImageOnly: false,
})
基本插件创建的jQuery文档。