通过点击事件利用form表单追加div做批量添加

通过点击事件利用from表单追加div

<script>
var i=0;定义变量  每次追加一个i就增加1
    function add(sid){
     $("form").append(
         "<div>"+
            "<table>"+
            "<tr>"+
             "<td><input type='text' name='pl["+i+"].pf'></td>"+
            "<td><input type='text' name='pl["+i+"].comment'></td>"+
            "<td><input type='hidden' name='pl["+i+"].sid' value='${sid}'></td>"+
            "</tr>"+
            "</table>"+
          "</div>"
            );
     i=i+1;
     }
   </script>

<body>
<input type="button" value="我要点评" onclick="add(${sid})">
<table >
 <tr>
 <td>序号</td>
 <td>评分</td>
 <td>评论内容</td>
 </tr>
 <c:forEach items="${zlist }" var="z">
 <tr>
 <td>${z.pid }</td>
 <td>${z.pf }</td>
 <td>${z.comment }</td>
 </tr>
 </c:forEach>
</table>
</body> 

 
<form>
    <!--<div>
             <table>
             <td><input type="text" name="pf"></td>
             <td><input type="text" name="comment"></td>
             <td><input type="hidden" name="sid" value="${sid}"></td>
                 </table>
         </div>-->
   </form>

批量添加
定义两个类 一个是要准备添加各个属性的类 一个是封装了集合的类

public class Pl {
private int pid;
 private double pf;
 private String comment;
 private int sid;
 public int getPid() {
  return pid;
 }
 public void setPid(int pid) {
  this.pid = pid;
 }
 public double getPf() {
  return pf;
 }
 public void setPf(double pf) {
  this.pf = pf;
 }
 public String getComment() {
  return comment;
 }
 public void setComment(String comment) {
  this.comment = comment;
 }
 public int getSid() {
  return sid;
 }
 public void setSid(int sid) {
  this.sid = sid;
public Pl( int pid,double pf, String comment, int sid) {
  super();
  this.pid = pid;
  this.pf = pf;
  this.comment = comment;
  this.sid = sid;
  //this.sname = sname;
 }
 public Pl() {
  super();
 }
 @Override
 public String toString() {
  return "Pl [pid=" + pid +" pf=" + pf + ", comment=" + comment + ", sid=" + sid + "]";
 }

封装了集合的类

public class ListPlForm {
private List<Pl> plf;  //集合的泛型的要添加的属性的类
public List<Pl> getPl() {
  return plf;
 }
 public void setPl(List<Pl> pl) {
  this.plf = pl;
 }
 public ListPlForm(List<Pl> pl) {
  super();
  this.plf = pl;
 }
 public ListPlForm() {
  super();
 }
 @Override
 public String toString() {
  return "ListPlForm [pl=" + plf + "]";
 }

进入controller

@RequestMapping("/tj")
 @ResponseBody
 public boolean tj(ListPlForm plf) { //传进来的参数的封装了集合的类
 List<Pl> pl = plf.getPl();//得到集合
     for (Pl pl2 : pl) {//遍历集合 得到对象  循环添加
      cs.tj(pl2);
  }
  return true;
  }
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值