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.