
2014-07-07  ≈ π; | 發布者:梁國('£←guó)芳 |  ♠γ₹; 查看(kàn):3320次
app開(kāi)發If you already have a jQuery* plu≠δλ¶gin that uses the fu ≥nctions we implement, your code shδ✔↓₩ould be fairly easy to port over¶β. For the most part, you will just n×eed to change the referenceλ♦ in the IIFE (Immediately Invoked ♥↓✘♥Function Expression)✔α≥☆ from "jQuery" to "jδ&q".
First, this document will il★±₹lustrate the basic s∞≈tructure for creating a plu ₹gin, then demonstrate how to creat<∞₩e a utility plugin. Finally thλεis page will share how to create a pl≤♠≠ ugin that acts upon elements in a buck≥±₽et.
The first step to createing a pl©±ugin is creating an IIFE (Immediately I¥≠↑nvoked Function Expression) $λ∞δand extend the $.fn object. For÷π example:
|
1
2
3
4
5
|
&nbφφΩsp; (function($){ &n♣∏bsp; $.fn.myPlugin=function(){ };})(af) |
The code above creates a simple f' unction that can then be accessed using•♦✔ the object returned b♦±≈y the $().myPlugin() function. Theπ∞★re are a few tips to remem∏σ$₹ber when operating inside the plugin.γ¥
Next, here is an example of how to ₩×make a utility plugin that does n↕$•ot act on objects.