form表单拼接

form表单拼接

一般我们添加信息会在另外一个jsp页面进行,然后想了一下能不能直接在当前页面的表单添加信息而不跳转页面,网上查了一些资料没有太大用处,要么牛头不对马嘴,要么高深莫测无法理解,想来想去最后还是使用append方法进行硬拼。
其中的$符号代表使用了jQuery的语法

 <script>
        $(document).on("click","#addUser",function () {
            var addInfor="<tr class='table table-bordered table-hover'>"+
                    "<td><input type=\"checkbox\" id=\"firstCb\" ></td>"+
                "<td ><input type=\"text\" class=\"form-control\" id=\"id\" name=\"id\" ></td>"+
                "<td><input type=\"text\" class=\"form-control\" id=\"name\" name=\"name\" ></td>"+
                "<td><input type=\"text\" class=\"form-control\" id=\"gender\" name=\"gender\"></td>"+
                "<td><input type=\"text\" class=\"form-control\" id=\"age\" name=\"age\" ></td>"+
                "<td><input type=\"text\" class=\"form-control\" id=\"address\" name=\"address\" ></td>"+
                "<td><input type=\"text\" class=\"form-control\" id=\"qq\" name=\"qq\" ></td>"+
                "<td><input type=\"text\" class=\"form-control\" id=\"email\" name=\"email\" ></td>"+
                    "<td width='242px' height='47px'>" +
                        "<button type='submit'  id='append' style='margin: 5px'>确定</button>" +
                        "<button type='submit'  id='cancel' style='margin: 5px'>取消</button></td>"+
                 "</tr>";
            $("table").append(addInfor);
            document.getElementById("cancel").onclick=function () {
                location.href="${pageContext.request.contextPath}/list.jsp"
            }
            document.getElementById("append").onclick=function (){

                document.getElementById("form").action="${pageContext.request.contextPath}/addServlet";
                document.form.submit();
            }

利用两个按钮的id绑定单击事件“确定”和“取消”,分别给定点击后的访问路径,点击确定后需要通过form表单提交信息。具体执行结果如下图
点击取消可以返回当前页面,也可以设置为返回上一页面的动作history.back(-1)
原本以为前端页面设计简单,只要用些模板和样式就可以解决,看来是我想太多了,作为一个程序初学者,路漫漫其修远兮~
现在使用Spring MVC分层设计,下一步学习springboot框架,又是一个大工程,加油加油加油!
2020.10.10记

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值