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