在jQuery中向datepicker小部件注入新方法

问题描述 投票:1回答:1

我试图在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
1个回答
1
投票

创建一个基本的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 documentation for basic plugin creation.

© www.soinside.com 2019 - 2024. All rights reserved.