fmpq.com
源代码:
点击运行
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Fmpq教程(fmpq.com)</title> </head> <body> <p>点击按钮计算数组所有元素相加的总和。</p> <button onclick="numbers.forEach(myFunction)">点我</button> <p>数组元素总和:<span id="demo"></span></p> <script> var sum = 0; var numbers = [65, 44, 12, 4]; function myFunction(item) { sum += item; demo.innerHTML = sum; } </script> </body> </html>
运行结果