关于table表格在MySQL中的整体存取
清风止雨 2017-11-22 03:12:02 在JS里做的自动建表,table里面每格都是一个INPUT 然后在input里面填了数据,提交之后取出来发现只有表格没有数据。
这是建表
function creatTable(){
var div = document.getElementById("resultDiv");
div.innerHTML = "";
var row1=$('#tubeNum option:selected').val();
//var row = document.getElementById("row").value;
var col1=$("#fiberNum option:selected").val();
//var col = document.getElementById("col").value;
var row2=$('#tubeNum1 option:selected').val();
var col2=$("#fiberNum1 option:selected").val();
var table = document.createElement("table");
table.setAttribute("id","inTable");
table.setAttribute("border","1");
for(var i= 0 ;i<(parseInt(row1)*2+1); i++){
var tr = document.createElement("tr");
tr.setAttribute("align","center");
for(var j =0 ; j<(parseInt(col1)+2);j++){
var td = document.createElement("td");
var input = document.createElement("input");
var div1 = document.createElement("div");
中间省略
odiv1.appendChild(oinput);
otd.appendChild(odiv1);
otr.appendChild(otd);
}
otd.setAttribute("align","center");
otd.setAttribute("style","width: 60px;height: 25px;");
}
otable.appendChild(otr);
}
}
div.appendChild(table);
div.appendChild(otable);
}
根据4个选项来控制2个表格的行和列
这是提交到后台插入到数据库
function submitcableTestAddForm(){
//有效性验证
if(!$('#cableTestAddForm').form('validate')){
$.messager.alert('提示','表单还未填写完成!');
return ;
}
//同步文本框中的备注
//materialAddEditor.sync();
//ajax的post方式提交表单
//$("#customAddForm").serialize()将表单序列号为key-value形式的字符串
var resultDiv = $('#resultDiv').html();
alert(resultDiv);
$("#formData").val(resultDiv.toString());
$.post("cableTest/insert",$("#cableTestAddForm").serialize(), function(data){
if(data.status == 200){
$.messager.alert('提示','新增成功!');
clearCableTestForm();
updateCableTestForm();
}else if(data.status == 0){
$.messager.alert('提示','缆号已存在');
clearCableTestForm();
updateCableTestForm();
}
else{
$.messager.alert('提示',data.msg);
}
}
);
}
这是form表单
<form id="cableTestAddForm" class="cableTestForm" method="post">
<div class="listDiv" >
<table cellpadding="5" style="display:inline">
<tr width="250px" >
<td >订单号:</td>
<td >
<input class="easyui-textbox" type="text" name="orderno" data-options="required:false"
style="width: 160px;"/>
</td>
</tr>
<tr>
<td>订单类型:</td>
<td>
<select id="type" class="easyui-combobox" name="ordertype" panelHeight="auto" style="width: 160px;"
data-options="editable:false" >
<option value="1">国际订单</option>
<option value="2">国内订单</option>
</select>
略
</td>
</tr>
<tr>
<td>商业长度:</td>
<td>
<input class="easyui-textbox" type="text" name="orderLenth" style="width: 160px;"/>
</td>
</tr>
略
<tr>
<td>备注:</td>
<td>
<input class="easyui-textbox" type="text" name="note" style="width: 160px;height:50px;"/>
</td>
</tr>
</table>
</div>
<input type="text" id="formData" name="formData" style="display:none"/>
<div id="resultDiv" class="resultDiv" >
</div>
<input type="hidden" name="materialParams"/>
</form>
自动建表的table 里面的input在实体类和数据库都没有对应的属性和字段,就只能一次把table的代码拿出来 整个放到一个字段里,但是在提交的时候 用alert(formData)发现只有表格代码,输入的数据 一个没有,这是什么情况?