获取多选input-选中后的值存数组

简介: 获取多选input-选中后的值存数组
<!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>

相关文章
|
前端开发
element ui el-table 多选 表头全选框替换文字
element ui el-table 多选 表头全选框替换文字
1444 0
|
6月前
全选或者单选checkbox的值动态添加到div
全选或者单选checkbox的值动态添加到div
26 0
|
9月前
使用 contenteditable=“true“ 实现的文本框全选内容
使用 contenteditable=“true“ 实现的文本框全选内容
41 0
|
JavaScript
关于复选框checkbox没有选中不能获取值的问题
关于复选框checkbox没有选中不能获取值的问题
140 0
关于复选框checkbox没有选中不能获取值的问题
|
前端开发
【解决方法】element-ui 中输入框input与下拉选择框没有在一条水平线上
【解决方法】element-ui 中输入框input与下拉选择框没有在一条水平线上
558 0
【解决方法】element-ui 中输入框input与下拉选择框没有在一条水平线上
动态添加input,然后获取所有的input框中的值
动态添加input,然后获取所有的input框中的值
【Layui】关于单选框的选中状态,下拉框默认显示
【Layui】关于单选框的选中状态,下拉框默认显示
598 0
【Layui】关于单选框的选中状态,下拉框默认显示