How does JQuery customize plug-ins -- $. fn usage, jquery. fn

Source: Internet
Author: User

How does JQuery customize plug-ins -- $. fn usage, jquery. fn


JQuery provides many plug-ins, which are roughly searched and cannot be described as follows:






I clicked a few and looked at the results. They found that they were quite exquisite. web development needed more aesthetics than Javascript. I can only say that JS is just a foundation.



It is a good news for developers. However, so many plug-ins sometimes not all meet our needs. For example, sometimes we only need a ship engine, but now we only have a ship. We also need to take the ship apart, or sometimes we don't need any parts at all. At this time, we need to do it ourselves.


For example, I have previously written a Tab control. Now I want to make it a plug-in. Let's take a look at this Demo:



First, write a separate JS file:



// JavaScript Document <span style = "color: # FF0000;"> <strong> // $. fn is the extension plug-in method </strong> </span> (function ($) {// form a closure and define the scope $. fn. miaovTab = function () {var This = this; $ (this ). find ('input '). click (function () {$ (This ). find ('input '). attr ('class', ''); $ (This ). find ('div '). fadeOut (); $ (this ). attr ('class', 'active'); $ (This ). find ('div '). eq ($ (this ). index ()). fadeIn () ;};};} (jQuery );




Then, add the following code to the page:




<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 



You can click the three buttons in the browser to switch the Tab.





Now, I have practiced creating plug-ins. When we encounter an inappropriate plug-in next time, we can hand-write or extract some of the source code from the Demo, and then use the code to make our own lightweight plug-ins.



PS: attaches a very beautiful JQuery plug-in Library: http://www.jq22.com/








Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.