实例代码“Ctrl+/”提示“F11/ESC”全屏 返回 格式化 恢复 运行
x
 
1
<!DOCTYPE html>
2
<html>
3
<head>
4
<meta charset="utf-8">
5
<title>手册网教程(shouce.ren)</title>
6
</head>
7
<body>
8
9
<p>点击按钮将数组中的所有值乘以特定数字。</p>
10
<p>乘以: <input type="number" id="multiplyWith" value="10"></p>
11
<button onclick="numbers.forEach(myFunction)">点我</button>
12
13
<p>计算后的值: <span id="demo"></span></p>
14
15
<script>
16
var numbers = [65, 44, 12, 4];
17
18
function myFunction(item,index,arr) {
19
    arr[index] = item * document.getElementById("multiplyWith").value;
20
    demo.innerHTML = numbers;
21
}
22
</script>
23
24
</body>
25
</html>