Js循环清空form表单信息

当页面是添加的时候可以使用

 <input type="reset" name="reset" value="重置">

当页面是修改的时候,想要清空input的value使用循环清空

<script>                
$(function () {

        $(".reset").click(function () {
            /*循环清空所有按钮的信息*/
            $(".detailTable input").each(function(){
                $(this).val('');
            });
        })

    })
    </script>

拿走代码的记得点赞

在这里插入代码片
	<form action=#" method="post">
                    <table class="detailTable">
                        <tr>
                            <td>姓名</td>
                            <td><input type="text" name="name" value="${test.name}"></td>
                        </tr>
                        <tr>
                            <td>年龄</td>
                            <td><input type="text" name="age" value="${test.age}"></td>
                        </tr>
                        <tr>
                            <td>性别</td>
                            <td><input type="text" name="sex" value="${test.sex}"></td>
                        </tr>
                    </table>
                    <input type="submit" value="确定">
                    <input type="button" class="reset" value="重置">
                </form>
<script>                
$(function () {

        $(".reset").click(function () {
            /*循环清空所有按钮的信息*/
            $(".detailTable input").each(function(){
                $(this).val('');
            });
        })

    })
    </script>

猜你喜欢

转载自blog.csdn.net/qq_44739706/article/details/111561001