【Java】前端以form表单提交表格数据,亲测可用

1.javascript前端实现以form表单提交表格数据到后端,代码片段如下:

<script type="text/javascript">
    /**
     * form表单提交表格数据
     */
    function testform(evt) {
      var url = "info_information";
      var curtd = $(evt).parent().parent().find("td");
      var paraData = {
        "name":curtd.eq(0).text(),
        "pattern":curtd.eq(5).text(),
        "x":curtd.eq(6).text(),
        "a":curtd.eq(7).text(),
        "d":curtd.eq(8).text(),
        "c":curtd.eq(9).text(),
        'self_ip':curtd.eq(10).text(),
        'bit_ip':curtd.eq(11).text(),
        'group_ip':curtd.eq(12).text(),
        'gateway_ip':curtd.eq(13).text(),
        'server_ip1':curtd.eq(14).text(),
        'server_ip2':curtd.eq(15).text()
      };
      var form = $("<form method='post'></form>");
      form.attr({"action":url});
      console.log(paraData);
      for (arg in paraData){
        var input = $("<input type='hidden'>");
        input.attr({"name":arg});
        input.val(paraData[arg]);
        form.append(input);
        console.log(input)
      }
      $("body").append(form);
      console.log(form);
      form.submit();
    }
  </script>

2.table表格代码片段如下:

<table class="table table-hover text-center">
      <thead>
      <tr>
        <th>设备编号</th>
        <th>设备类别</th>
        <th>运行状态</th>
        <th>网络状态</th>
        <th style="display:none">录音状态</th>
        <th style="display:none">通讯模式</th>
        <th style="display:none">X反馈</th>
        <th style="display:none">A反馈</th>
        <th style="display:none">D反馈</th>
        <th style="display:none">C反馈</th>
        <th style="display:none">设备地址</th>
        <th style="display:none">BIT地址</th>
        <th style="display:none">组播地址</th>
        <th style="display:none">网关地址</th>
        <th style="display:none">服务地址1</th>
        <th style="display:none">服务地址2</th>
        <th>更新时间</th>
        <th >操作</th>
      </tr>
      </thead>
      <tbody>
      <c:forEach var="item" items="${map1}" varStatus="i" end="32" step="1">
        <tr>
          <td>
              ${item.name}
          </td>

          <td>
            <c:if test="${item.name == 0}">A型终端</c:if>
            <c:if test="${item.name > 0 && item.name < 32}">D型终端</c:if>
            <c:if test="${item.name == 32}">A[便携式]</c:if>
          </td>

          <td>
            <c:if test="${state[i.count-1] == 0}"></c:if >
            <c:if test="${state[i.count-1] == 1}">运行正常</c:if>
          </td>

          <td>
            <c:if test="${state[i.count-1] == 1}">网络正常</c:if >
            <c:if test="${state[i.count-1] == 0}"></c:if>
          </td>

          <td style="display:none">
            <c:if test="${state[i.count-1] == 1} && ${item.record == 1}">正在录音</c:if>
            <c:if test="${state[i.count-1] == 0}">无录音</c:if >
          </td>

          <td style="display:none">
            <c:if test="${item.pattern == 0}">广播</c:if>
            <c:if test="${item.pattern == 1}">组播1</c:if>
            <c:if test="${item.pattern == 2}">组播2</c:if>
            <c:if test="${item.pattern == 3}">组播3</c:if>
            <c:if test="${item.pattern == 4}">组播4</c:if>
            <c:if test="${item.pattern == 5}">点播</c:if>
            <c:if test="${state[i.count-1] == 0}">空闲 </c:if>
          </td>

          <td style="display:none">
            <c:if test="${state[i.count-1] == 1}">${item.x}</c:if >
            <c:if test="${state[i.count-1] == 0}">0.0</c:if >
          </td>

          <td style="display:none">
            <c:if test="${state[i.count-1] == 1}">${item.a}</c:if >
            <c:if test="${state[i.count-1] == 0}">0.0</c:if >
          </td>

          <td style="display:none">
            <c:if test="${state[i.count-1] == 1}">${item.d}</c:if >
            <c:if test="${state[i.count-1] == 0}">0.0</c:if >
          </td>

          <td style="display:none">
            <c:if test="${state[i.count-1] == 1}">${item.c}</c:if >
            <c:if test="${state[i.count-1] == 0}">0.0</c:if >
          </td>

          <td style="display:none">
            <c:if test="${state[i.count-1] == 0}">0.0.0.0</c:if >
            <c:if test="${state[i.count-1] == 1}">${item.self_ip}</c:if >
          </td>

          <td style="display:none">
            <c:if test="${state[i.count-1] == 0}">0.0.0.0</c:if >
            <c:if test="${state[i.count-1] == 1}">${item.bit_ip}</c:if >
          </td>

          <td style="display:none">
            <c:if test="${state[i.count-1] == 0}">0.0.0.0</c:if >
            <c:if test="${state[i.count-1] == 1}">${item.group_ip}</c:if >
          </td>

          <td style="display:none">
            <c:if test="${state[i.count-1] == 0}">0.0.0.0</c:if >
            <c:if test="${state[i.count-1] == 1}">${item.gateway_ip}</c:if >
          </td>

          <td style="display:none">
            <c:if test="${state[i.count-1] == 0}">0.0.0.0</c:if >
            <c:if test="${state[i.count-1] == 1}">${item.server_ip1}</c:if >
          </td>

          <td style="display:none">
            <c:if test="${state[i.count-1] == 0}">0.0.0.0</c:if >
            <c:if test="${state[i.count-1] == 1}">${item.server_ip2}</c:if >
          </td>

          <td>
              ${maptime}
          </td>
          <td>
            <button type="submit" class="button border-main" onclick="testform(this)" ><span class="fa fa-info"></span> 详情</button>
          </td>
        </tr>
        </c:forEach>
        <tr>
          <td colspan="8"></td>
        </tr>
      </tbody>
    </table>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

九点两刻

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值