首页 > 其他 > 详细

for 的相关用法

时间:2018-05-19 11:39:28      阅读:117      评论:0      收藏:0      [点我收藏+]

forEach()

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>forEach</title>
</head>
<body>

<p>点击按钮将数组中的所有值乘以特定数字。</p>
<p>乘以: <input type="number" id="multiplyWith" value="10"></p>
<button onclick="numbers.forEach(myFunction)">点我</button>

<p>计算后的值: <span id="demo"></span></p>

<script>
var numbers = [65, 44, 12, 4];

function myFunction(item,index,arr) {
    arr[index] = item * document.getElementById("multiplyWith").value;
    demo.innerHTML = numbers;
}
</script>

</body>

 

for 的相关用法

原文:https://www.cnblogs.com/loveMis/p/9059666.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!