JavaScript算术运算符包括加法,减法,除法,乘法。让我们来看一些
<html> <body> <p id="add"></p> <script> var tot = 0; var a = [1,2,3,4,5,6,7,8,9] for (var i = 0; i < a.length; i++) { if(a[i]%2 == 0) { tot += a[i] } } document.getElementById("add").innerHTML = tot; </script> </body> </html>
20
<html> <body> <p id="mul"></p> <script> var pro = 1; var a = [1,2,3,4,5,6,7,8,9] for (var i = 0;i<a.length;i++) { pro *= a[i] } document.getElementById("mul").innerHTML = pro; </script> </body> </html>
362880