1. Encapsulate the static plug-in Create a jquery file inside can encapsulate multiple methods named format multi-bit jquery. [Plugin name].js
$.extend ({add:function (A, b) {return a+b;}}); $.extend ({mins:function (A, B) {return-A-B;}});
2. Encapsulated member function plug-ins can also be understood as dynamic plug-ins to create a jquery file inside can encapsulate multiple methods named format multi-bit jquery. [Plugin name].js
$.fn.extend ({alertwhileclick:function () {alert (22); } }); $.fn.extend ({aa:function () {alert (22777); } });
The best way to write
;(function ($) {/* Put the plug-in code here, you can add $ as a jquery alias */$.fn.extend ({alertwhileclick:function () {A Lert (22); } }); $.fn.extend ({aa:function () {alert (22777); }}); $.extend ({bb:function () {return 555; } }); }) (JQuery);
jquery Encapsulation Plugin