JavaScript converts data types and javascript converts data types.
All languages have the ability to convert data types, and javascript is no exception. It also provides developers with a large number of type conversion access methods. This article will share with you how js achieves mutual conversion of data types, the details are as follows:
String Conversion number var a = '1'; console. log (+ a); console. log (a ++); console. log (-a + 3); console. log (parseInt (a); console. log (parseFloat (a); console. log (Number (a); Numeric conversion String var a = 1; a + ''String (a);. toFixed ();. toLocaleString ();. toPrecision ();. toString (); array to string var arr = [1, 2, 3]; arr. toString (); arr + ""; array to numeric, only one digit, otherwise NaNvar arr = [1]; ++ arr; + arr; arr --; arr-0arr.toString ()-0
The data obtained by js is of the string type by default. If you perform a numerical operation, you must use parseInt to convert the data to a numerical value.
Html code:
Copy codeThe Code is as follows:
<Div id = "archive">
<Input type = "hidden" name = "page" value = "1"/>
</Div>
Js Code:
$ ("# Archive "). bind ('click', function () {var page = $ ("input [name = 'page']"). val (); // calculate the value using parseInt $ ("input [name = 'page']"). val (parseInt (page) + 1 );});
The above is all the content of this article, hoping to help you learn.
Articles you may be interested in:
- Javascript data type conversion (parseInt, parseFloat)
- Js data type conversion summary notes
- Use parseInt for data type conversion during js numeric calculation (jquery)
- Basic Javascript tutorial-data type conversion
- JavaScript data type and conversion
- Summary of data type conversion methods in JavaScript
- A Brief Introduction to implicit conversions of JavaScript Data Types