<label> <input type="checkbox" />测试结果 </label>
<script> document.getElementsByTagName("input")[0].onclick = function(){ if(this.checked == true){ var t1 = new Date().getTime(); //方法二 += for (i = 0; i < arr.length; i++) { tmp += arr[i] } console.log(tmp); var t2 = new Date().getTime(); console.log(t2 - t1) //34ms }; } var arr = [], tmp = 0; for (var i = 0; i < 1000000; i++) { arr.push(i * 12) } var t1 = new Date().getTime(); //方法一 eval console.log(eval(arr.join("+"))); var t2 = new Date().getTime(); console.log(t2 - t1) //475ms </script>