我试图在jquery中注入一个新方法。基本上,我有一个从jQuery min文件加载的datepicker。现在,我想在加载此datepicker时注入一个新方法dateCompliance()。
$("#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,
})