Summary of jquery plugin notation
Web front-end technologies such as jquery are increasingly being used in recent Web applications. These technical frameworks effectively improve the user's operational experience while also improving the developer's efficiency in structuring the rich client UI. jquery itself provides a wealth of operations, but sometimes we need to construct some of our most common front-end UI components based on our own business and system features (style), and jquery's plugins give us a better way to construct these UI components, so we can reuse them again later. There are also many articles on jquery plugins on the web, and I have searched for them, but these documents are too discrete, not effectively organized and fully explained how the Jquey plugin should be written, and in what form and under what circumstances. Below, I'll explain the common uses of jquery plugins and the common scenarios for these plugins. First, before specifying the plugin, let's assume a usage scenario: There is an HTML page (or. aspx page), and a 5-row, 3-column table is placed on the page, the:<table></table> tag, with the following code: <table id= "newtable" > <tr> <td>1</td><td> 1</td><td>1</td> </tr> <tr> <TD >1</td><td>1</td><td>1</td> </tr> <tr> <td>1</td><td>1</td><td>1</td> </TR > <tr> <td>1</td><td>1</td><td>1</ td> &NBsp </tr> <tr> <TD>1</TD><TD>1</TD><TD >1</td> </tr></table> My function is to move the mouse over a row in the table, the current row is highlighted, and the other rows are normal. OK, in conjunction with this scenario, we'll explore how to use the jquery plugin to achieve the above functionality. The common jquery plugin has the following wording: 1. The extension to jquery itself, as its name implies, is the extension of jquery's own library of methods. In use by the time of the $. MethodName () is used in a direct manner. Plug-In code example: $.extend ({ handletableui:function (table) { var thistable = $ ("#" + table); $ (thistable). Find ("tr"). Bind ("MouseOver", function () {& nbsp $ (this). CSS ({color: "#ff0011", Background: "Blue"}); }); &n Bsp $ (thistable). Find ("tr"). Bind ("Mouseout", function () { $ (thi s). css ({color: "#000000", Background: "White"}); }); }); Example description: When you want to extend the jquery itself $.extend (), the Extend () method of jquery willProvides a way to extend jquery itself, in the Extend () method, we use {...} In the form of a specific method body. The most important of these is to define our own extension methods, such as the Handletableui in the example. Defined by: Method name: Function (parameter) {method body}. In this way we can define jquery's own extension method, and this method can be displayed through smart hints on the Web page. The code that is called in the page is as follows: <script type= "Text/javascript" > $ (document). Ready (function () { $.handletableui ("newtable"); }); </script> 2. Extending the use of HTML markup or page elements using this plug-in, when using this plug-in, you need to first reference a jquery-wrapped page element, such as $ ("#tableId"). Method (). Plug-In Code examples: (function ($) { $.fn.settableui = function (options) { var defaults = { Evenrowclass: "Evenrow", Oddrowclass: "Oddrow", Activerowclass: "Activerow" } &NBS P var options = $.extend (defaults, options); This.each (function () { &NB Sp var thistable=$ (this); &NBSP $ (thistable). Find ("tr"). Bind ("MouseOver", function () { &NBS P $ (this). CSS ({color: "#ff0011", Background: "Blue"}); }); &N Bsp $ (thistable). Find ("tr"). Bind ("Mouseout", function () { &NBSP ; $ (this). CSS ({color: "#000000", Background: ' White '}); }); & nbsp }); };}) (jquery); example: When you want to make a jQuery extension to a page element, you need to use (function ($) {...}) (JQuery), the way to develop. In the "..." section, define our own method, defined by: $.fn. Custom Method name = function (parameter) {...}; Defines the specific content of the extension method. When the page is called, it differs from the extension of jquery itself. The specific calling code is as follows: <script type= "Text/javascript" > $ (document). Ready (function () { $ ("#newTable"). Settableui (); }); </script> 3. Instead of explicitly invoking jquery on the page, you can implement a call to that plug-in by simply adding a jquery plug-in script reference. In general, if you need to use some of the global jquery plug-ins, that is: plug-in methods do not need to explicitly call, but to reference the script, and this plug-in generally to the entire Web pageThe role of the face to global configuration or settings, such as: The overall layout of <body></body> internal content, which can be implemented by script reference. Plug-In code example: (Function ($) { $.tableui = {set:function () { var thistable = $ ("table") ; $ (thistable). Find ("tr"). Bind ("MouseOver", function () { &NB Sp $ (this). CSS ({color: "#ff0011", Background: "Blue"}); }); $ (thistab Le). Find ("tr"). Bind ("Mouseout", function () { $ (this). CSS ({color: "#000000", BAC Kground: "White"}); }); } }; //This requires self-invocation $ (function () { $.tableui.set (); });}) (jQuery); example: If the above code is in the My.plugin.js file, then we just need to add a reference to the script file on the page, as follows: <script src= "Scripts/my.plugin.js" Type= "Text/javascript" ></script>, of course, in all the places where jquery is used, you need to first add a reference to the jquery library script. In the code of the reference plug-in, the main thing is in the plug-in to actively invoke their own written plug-in method, the above code has comments on the place。 Otherwise, the plugin code we write will not work. ok, the above is my jquery plug-in some of the understanding of the hope that we can help, but also hope that you can use the process of timely feedback related information.
How jquery plugins are spelled