<script><BR> var i="123abc";<BR> i=parseInt(i);//字符串转整形<BR> alert(i+","+typeof(i));//输出:123,number<BR> i="12.3abc";<BR> i=parseFloat(i);//字符串转浮点型<BR> alert(i+","+typeof(i));//输出:12.3,number(可见不管是int还是float都是number类型)<BR> i="a123abc";<BR> i=parseInt(i);//字符串转整形<BR> alert(i+","+typeof(i));//输出:NaN,number (由于转换失败,所以提示“不是一个数字,Not a Number”)<BR> var num=document.getElementById("num").value;<BR> function showMsg(num)<BR> {<BR> for(var i=0;i<num;i++)<BR> {<BR> document.write("你好,JavaScript!<br/>");<BR> }<BR> }<BR></script>