jquery获取多个相同name的input框的value值

<!DOCTYPE html>
<html lang="zh">
<head>
  <meta charset="UTF-8">
  <title>Document</title>
</head>
<script src="http://www.jq22.com/jquery/jquery-3.3.1.js"></script>
<body>
<form method="post" enctype="multipart/form-data">
    早餐:<input type="text" name="goods" /><br>
    午餐:<input type="text" name="goods" /><br>
    晚餐:<input type="text" name="goods" /><br>
    <input type="button" name="sub" class="sub" value="提交" />
</form>
</body>
<script>
    $('.sub').click(function () {
        var arr =[];
        $("input[name='goods']").each(function(){
            arr.push($(this).val());
        })
        console.log(arr);
    });
</script>
</html>

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_42249896/article/details/86476229