Simple.
Test.js
;(function ($) { $.fn.getdata=function (options) { return this.append (options); }) (JQuery);
Test.html
<! DOCTYPE html>
A little more complicated.
Test2.js
(function ($) {debugger; Within our plugin container, create a public variable to build a private method var privatefunction = function () {//code here}//Create an object by literal, store the common party we need var methods = {//In the literal object defines each individual method Init:function () {//For better flexibility, for each of the selectors from the main function and into each method Separate elements execute code return This.each (function () {//Create a jquery object for each individual element var $this = $ (th IS); Execute code//For example: Privatefunction (); }); }, Destroy:function () {//Executes method return This.each () for each element of the selector (function () {//Execute generation Code}); } }; $.fn.pluginname = function () {///Get our method, unfortunately, if we use function (method) {} to implement, this will ruin everything var method = Arguments[0] ; Verify if the method exists if (Methods[method]) {//If the method exists, store it for use//NOTE: I'm doing this to make it easier to use each () method = Methods[method]; If the method does not exist, verify that the object is an object (JSON object) or that method methods are not passed in} else if (typeof (method) = = ' object ' | | !method) {//If we pass in an object parameter, or there is no argument at all, the Init method is called method = Methods.init; } else {//If the method does not exist or the parameter does not pass in, an error is reported. The method that needs to be called is not called correctly $.error (' method ' + method + ' does not exist on Jquery.pluginname '); return this; }//Call our chosen method//again notice how we transfer each () from here to return Method.call (this) on each individual method; }}) (JQuery);
Test2.html
<! DOCTYPE html>
Special attention to the second case, if you read my previous principle is not clear, please source debugging, step by step to see the jquery source design mode.
Customizing the build jquery Plug-in Experiment (2)