Jquery encapsulation (learning) 01, jquery encapsulation learning 01

Source: Internet
Author: User

Jquery encapsulation (learning) 01, jquery encapsulation learning 01

1. during the development process, we often use repeated jquey code. The most common is where we need to copy and paste the code, which greatly increases the redundant code and makes maintenance inconvenient. Why don't we encapsulate the common jquery code and call it wherever necessary?

2. From now on, I have learned how to encapsulate jquery code and started the first jquery encapsulation.

3. you can use jquery to write your own function or library like the original JS, and then reference your js when calling it, and ensure that jquery is also referenced on the page, for example, you write an extension. Then you can reference it on the page in saygoodbye. js.

JQuery. saygoodbye = function () {alert ("good bye"); $ ("body"). hide ();}

4. Page call encapsulated jquery

 

5. effect:

 

6. Of course, this is just the simplest jquery encapsulation. In actual project practice, we also need to pay attention to namespaces and other complicated problems.

 

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.