Chrome59到底支不支持forEach函数?


饮歌长啸 2019-03-03 08:04:35

<!DOCTYPE HTML>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<title>无标题文档</title>

</head>    

<body>

<form>

请选择你爱好:<br>

<input type="checkbox" name="hobby" id="hobby1">  音乐

<input type="checkbox" name="hobby" id="hobby2">  登山

<input type="checkbox" name="hobby" id="hobby3">  游泳

<input type="checkbox" name="hobby" id="hobby4">  阅读

<input type="checkbox" name="hobby" id="hobby5">  打球

<input type="checkbox" name="hobby" id="hobby6">  跑步 <br>

<input type="button" value = "全选" onclick = "checkall();">

</form>

<script type="text/javascript">

function checkall(){

var hobby = document.getElementsByTagName("input");

hobby.forEach(function(v){v.checked=true;}); //为什么chrome这句报函数forEach不存在?

[1,2,3].forEach(function(v){alert(v);});//而这句就不报错呢?

}

</script>

</body>

</html>




小唯快跑啊
浏览 418回答 4
4回答
打开App,查看更多内容
随时随地看视频慕课网APP