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

以下是H5代码以及jQuery代码

H5代码以及jQuery代码
<body style="width: 100vw;margin: 0 auto;padding: 0vw;">
    <form>
        问题1:<input type="text" name="question" /><br>
        问题2:<input type="text" name="question" /><br>
        问题3:<input type="text" name="question" /><br>
        问题4:<input type="text" name="question" /><br>
        问题5:<input type="text" name="question" /><br>
        问题6:<input type="text" name="question" /><br>
        <input type="button" class="btn" value="提交" />
    </form>
</body>
<script>
    $('.btn').click(function () {
        let arr = [];
        $("input[name='question']").each(function () {
            arr.push($(this).val());
        });
        console.log(arr);
    });
</script>

输出结果

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

posted @ 2021-11-25 13:19  TomLucas  阅读(256)  评论(0编辑  收藏  举报