Some of the ideas of jquery, some of their own insights!!!!

Source: Internet
Author: User

I summed up some of the underlying jquery ideas, purely personal insights.

Now, to facilitate the description, the customer now gives us a need:

There are two buttons on the page, a picture that hides the image when I click the Hidden button, and displays the picture when I click the Show button. What would you do if you were to do that?

Method one: Using DOM technology to navigate to the button, when the button is clicked to trigger the JS onclick event and then throw a function, in the function using the DOM to position the picture, and then modify the visibility property of the picture.

"Improvement

Method Two: Method one can be completed, but the operation is more cumbersome. When we think of object-oriented, we can encapsulate the picture on the page and have two behaviors for the picture, namely "show" and "hidden", and when the button is clicked, the JS onclick event is triggered and a function is thrown, in which we instantiate the picture object and invoke the object's behavior (" Show "," hidden ").

"Improvement

Method Three: Method two to the method of a package, simplifying a part of the code, but we are very lazy people, or think the code is too long, writing inconvenient, then what should we do? Right!! is to encapsulate the JavaScript again, and then we just have to write the code according to our own rules. For example $ ("#ID"), its essence is a function, $ is actually just a method name, #ID是函数的形参, this gives us a false impression, is only need to call this function to be able to locate a node, in fact, it comes down to the bottom of the implementation, it still uses some of the more traditional forms, Similar to document.getElementById ();d ocument.getelementsbytagname ();d ocument. Elementsbyname ();

Some of the ideas of jquery, some of their own insights!!!!

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.