简单教程
提交运行
代码编辑器:
<p id="demo">单击按钮将不同的对象值转换为数字</p> <button onclick="myFunction()">点我</button> <script> function myFunction(){ var test1 = new Boolean(true); var test2 = new Boolean(false); var test3 = new Date(); var test4 = new String("999"); var test5 = new String("999 888"); var n = Number(test1) + "<br>" + Number(test2) + "<br>" + Number(test3) + "<br>" + Number(test4) + "<br>" + Number(test5); document.getElementById("demo").innerHTML=n; } </script>
运行结果: