recently, many netizens sayJqueryWhat is a plugin? How do you write that? I can't write?
a lot of questions do not know how to answer them at the moment, the personal think is the netizen to complicate the problem.
In fact, some of the commonly used, practical, universal functions encapsulated and, in short, is to put these code in a method, you can achieve the effect of repeated use, so that you do not need to use this function every time to write again.
now jquery is added to the concept of plug-ins, as long as it is in accordance with its specific format as usual writing function to write it, not though it is too complex. Believe it or not, I believe it anyway.
next with a simple code to explain, if the netizens have read the plugin will not write, I can only no language
First step: Define the plugin
- $ (function () {
- $.fn. Plug-in name = function (options) {
- var defaults = {
- Event: "Click",//Trigger response Event
- Msg: "Holle word!"//display content
- };
- var options = $.extend (defaults,options);
- var $this = $ (this); Of course the response event object
- Function Code Section
- Binding events
- $this. Live (options. Event,function (e) {
- alert (options.msg);
- });
- }
- });
- Copy Code
Copy Code
Step Two: Call the plugin
- $ (function () {
- Binding element Events
- $ ("#test"). Plug-in name ({
- Event: "Click",//Trigger response Event
- msg: "The plugin turned out to be so simple!"//display content
- });
- });
- <input type= "button" id= "Test" value= "This is a simple plug-in call"/>
- Copy Code
Copy Code
after reading, I believe that netizens should understand it! jquery Plugin is so simple original addresshttp://www.00h5.com/thread-2097-1-1.html
Teach you to write jquery plugins