<!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>循环多条选中input值 值存数组-获取选中input存数组</title> </head> <body> 循环多条选中input值 值存数组-获取选中input存数组 <input type="checkbox" name="Fruit" value="1" checked="checked" /> <input type="checkbox" name="Fruit" value="2" checked="checked" /> <input type="checkbox" name="Fruit" value="3" checked="checked" /> </body> <script type="text/javascript"> var nodeValue = []; function getValue(Fruit){ var node = document.getElementsByName(Fruit); var len = node.length; for (var i = 0; i < len; i++) { if (node[i].checked) { nodeValue.push(node[i].value); } } } getValue("Fruit"); console.log(nodeValue); </script> </html>