JS (1)-Get DOM objects and code

Source: Internet
Author: User

I found some small problems in my work today. I checked it online to find out that my Js is the tip of the iceberg. I will learn from others with an open mind in the future.

1. Differences between obtaining DOM objects by JS and jquery

I used to think that the two are the same. I recently learned that the two are different.

The former uses var jstab = Document. getelementbyid ("tab"); // Where tab is the attribute value of the selected DOM object ID.

The latter var jqtab = $ ("# tab"); // not only requires the ID attribute value, but also needs to add #, which is specified by jquery.

Using Native js to obtain DOM objects, while using jquery to wrap DOM objects, how can jquery objects be converted to DOM objects? It's easy to get jqtab. Get (0), that is, you can get the first array element. Although the jquery object is not an array, it can be understood as an array. What is the opposite? Jqtab = $ (jstab)
It's easy, everybody.

2. Differences between encodeuricomponent and encodeuri

When passing parameters to the backend, the two functions in JS need to be used for Chinese encoding. What is the difference between the two functions? The result obtained from the Internet is as follows:

Encodeuricomponent (Params) This method does not encode ASCII letters and numbers, and does not encode these ASCII punctuation marks :-_.! ~ *'(). Other characters (such :;/? : @ & =+ $, # The punctuation marks used to separate URI components) are all replaced by one or more hexadecimal escape sequences. Encodeuri (Params) This method does not encode ASCII letters and numbers, and does not encode these ASCII punctuation marks :-_.! ~ *'(). The purpose of this method is to fully encode the URI. Therefore, the encodeuri () function will not escape the following ASCII punctuation marks with special meanings in the URI :;/? : @ & =+ $, # Press Ctrl + C to copy the code above from encodeuricomponent of w3cschool and encodeuri of w3cschool

That is to say, ;/? : @ & = + $, # The former is required when encoding is required. Where is the purpose of the two? The former is used for post parameter transfer, and the latter is used for URL jump. For personal understanding, please kindly advise if it is incorrect.

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.