Copy code The code is as follows: <br> var i="123abc ";<br> i=parseInt(i);//Convert string to integer<br> alert(i "," typeof(i));//Output: 123, number<br> i="12.3abc"; <br> i=parseFloat(i);//Convert string to floating point type<br> alert(i "," typeof(i));//Output: 12.3, number (it can be seen that whether it is int or float, it is number Type)<br> i="a123abc";<br> i=parseInt(i);//Convert string to integer<br> alert(i "," typeof(i));//Output: NaN, number ( Because the conversion failed, the prompt "Not a Number") <br> var num=document.getElementById("num").value;<br> function showMsg(num)<br> {<br> for( var i=0;i<num;i )<BR> /script><br><br><br> </div>