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>