This time the main record is the type conversion in JavaScript and three encoding functions.
One, type conversion
Type conversions in JavaScript, which belong to global objects.
parseint (string); Converts a string to an integer parsefloat (string); To convert a string to a floating-point type
Number turns into String type:
Num.tostring (); num.tostring (2); Display Num.tostring (8) in binary form; num.tostring (16);
Two or three encoding functions (ref. W3school)
Encoding functions become URIs, a more important use is to ensure that some special characters can be in different places (such as client, server side) can be normal parsing.
1. encodeURI ();
Reference: http://www.w3school.com.cn/jsref/jsref_encodeuri.asp
A string can be encoded as a URI (a Universal Resource identifier).
Use: encodeURI (uristring), where certain characters are replaced by hexadecimal escape sequences.
The method does not encode ASCII letters and numbers, nor does it encode these ASCII punctuation marks:-_. ! ~ * ' ()
Such as:
document.write (encodeURI ("Http://www.w3school.com.cn/My first/"));
Output:
http://www.w3school.com.cn/My%20first/
2. encodeURIComponent ();
Reference: http://www.w3school.com.cn/jsref/jsref_encodeURIComponent.asp
The string is encoded as a URI component.
The difference from encodeURI:
Such as:
document.write (encodeURIComponent ("http://www.w3school.com.cn/p 1/"));
Output: (Space is%20)
http%3a%2f%2fwww.w3school.com.cn%2fp%201%2f
3. Escape ();
Reference: http://www.w3school.com.cn/jsref/jsref_escape.asp
Encoding a string allows the string to be read on all computers.
Such as:
document.write (Escape ("Visit w3school!");
Output:
Visit%20w3school%21
JavaScript Learning Notes (ii)