Sharp jquery-Reading Notes (1), jquery-Reading Notes

Source: Internet
Author: User

Sharp jquery-Reading Notes (1), jquery-Reading Notes

I recently transferred to the frontend and learned jquery for two months. I read the book "sharp jquery, I made a special blog to take notes on some of the knowledge I saw during my learning process.

Chapter 1:

I. jQuery objects and DOM objects

1. convert a jQuery object to a DOM object

This is not the case yet. The book says that if you are not familiar with jQuery object methods and do not have the required methods, you need to convert them when you have to use DOM objects. There are two conversion methods: [index] And get (index ). Because the jQuery object is an array-like object.

1 var $ cr = $ ("# cr"); // jQuery object 2 var cr = $ cr [0]; // DOM object 3 var cr = $ cr. get (0); // DOM object

2. convert a DOM object to a jQuery object

DOM objects are packaged with $ () to obtain a jQuery object.

Note: The methods of the two objects can only be used separately.

2. Comparison between window. onload and $ (document). ready ()

1. window. onload must wait for the webpage. Therefore, after the content is loaded, images are included before execution. The $ (document). ready () web page is executed after all DOM structures are drawn. It is possible that the related content of DOM elements is not loaded.

2. window. onload cannot be written at the same time and will overwrite it. $ (Document). ready () can be compiled and executed simultaneously.

3. window. onload is not abbreviated. $ (Document). ready (function () {...}) can be abbreviated as $ (function (){....})

Iii. Solve conflicts between jQuery and other libraries

1. Import the data to other libraries. After loading the data, you can use the $ shortcut key to transfer control to other JavaScript libraries through the jQuery. noConflict () function. $ () Is short for jQuery.

2. Customize shortcuts by directly calling jQuery. noConflict () and then assigning the shortcut key variables such as var $ j = jQuery. noConflict ().

3. If you still want to use the $ symbol, you can give control to other libraries and use it in jQuery () brackets. Second, after the control is transferred, the anonymous function is defined and the parameter $ is set. The $ inside the anonymous function is jQuery. The method code is described on page 31 of the book.

4. If the jQuery library is imported before other libraries, you can directly use "jQuery" to do some jQuery work. At the same time, you can use the $ () method as a shortcut for other libraries. No need to hand over control

 

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.