<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>