All languages have the ability of type conversion, JavaScript is no exception, it also provides developers with a large number of types of transformation visits, this article for everyone to share JS implementation of data types of mutual conversion, the specific contents 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);
A.tofixed ();
A.tolocalestring ();
A.toprecision ();
A.tostring ();
Array-string
var arr = [1,2,3];
Arr.tostring ();
Arr+ "";
Array to number, only one bit, otherwise nan
var arr = [1];
++arr;
+arr;
arr--;
arr-0
arr.tostring ()-0
JS gets the data by default is string type, if the operation of numeric value must use parseint to convert to numeric operations.
HTML code:
Copy Code code 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 ();
The value to use parseint
$ ("input[name= ' page ')"). Val (parseint (page) +1);
});
The above is the entire content of this article, I hope to help you learn.