将html表格中的数据存储到数据库,搞了很久还是没搞定!!!!新手请大家帮帮忙吧,分一定送结帖率真百分百!!
我用的是MVC框架,html中的数据是从xml文件中获取的,table中的每行中有两个checkbox,第一个用来选中该行,第二个用来选择是否启用textbox。现在的情况是把选中行的数据传到后台然后再放入数据库中。写了段js代码,从表格中获取了数据,但获取的数据都堆放在一起了,表格中的每一列对应数据库中的每个字段,怎样把输出的那堆数据拆开并传入后台,最终存入数据库呢?请高手指点一下,非常感谢。用其它方法也行听网友说用jquery比较方便,但本人新手请大家帮忙。
后台代码应该怎样写?或前台代码应该怎样更改多谢。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script type="text/javascript">
//控制textbox
window.onload = function () {
$(".chk").each(function (i, j) {
$(this).next().attr("disabled", "disabled");
$(j).click(function () {
if ($(this).attr("checked"))
$(this).next().attr("disabled", "");
else
$(this).next().attr("disabled", "disabled");
});
});
};
</script>
<script type="text/javascript">
function bianli() {
var xxx = new Array();
var hiddenvalue_Step_No = "";
var hiddenvalue_Step_Name = "";
var hiddenvalue_Append_Name = "";
var tbl = document.getElementById("flowtbl");
var tbodys = tbl.tBodies; //获取表格中所有 tBody 对象的集合.
for (var i = 0; i < tbodys.length; i++) {
var rows = tbodys[i].rows;//集合中的行数
/// alert(i+"i");
for (var j = 0; j < rows.length; j++) {
//alert(j+"j");
var cells = rows[j].cells;//定义行内单元格集合
var spans = rows[j].getElementsByTagName("span");//返回标签为span的对象
for (var t = 0; t < cells.length; t++) {
//alert(t+"t");
var inputs = cells[t].getElementsByTagName("input");//返回标签为input的对象
if (inputs.length > 0) {
if (inputs[j].type == "checkbox" && inputs[j].checked == true) {
var tdlist = cells[t].parentNode.childNodes;//
for (var d = 0; d < tdlist.length; d++) {
//alert(d+"d");
var spans2 = tdlist[d].getElementsByTagName("span");
if (spans2.length > 0) {
for (var k = 0; k < spans2.length; k++) {
hiddenvalue_Step_No += (spans2[k].innerHTML + ",");
}
}
else {
continue;
}
}
}
}
}
xxx[j] = hiddenvalue_Step_No;
var hidcontrol = document.getElementById("<% = hidvalue.ID%>");
hidcontrol.value = xxx[j];
hiddenvalue_Step_No = "";
$("#hidvalue).val(xxx[j]);
}
}
document.form[0].submit();
}
</script>
<head id="Head1" runat="server">
<title>设计</title>
</head>
<body>
<form id="form1" runat="server">
<div id="interface_inside">
<div id="interface_quick">
<div class="interface_quick_left">
您现在的操作 >> 设计
</div>
</div>
<div id="interface_main">
<div id="tabs_config" class="tabsbox">
<div class="clearboth">
</div>
<!-- 模块 -->
<div id="config_basic1" class="tabs_wrapper">
<div id="PanelConfig">
<div class="blank_10">
</div>
<table class="table subsubmenu">
<thead>
<tr>
<td class="style3">
设计
</td>
</tr>
</thead>
</table>
<div id="PanelDefault">
<table class="table">
<tr>
<th style="font-weight: bold;" class="style7">
*名称:
</th>
<td class="style4">
<%=Html.TextBox("Flow_ModelName")%>
</td>
</tr>
<tr>
<th style="font-weight: bold;" class="style8">
*备注:
</th>
<td class="style6">
<%=Html.TextBox("Remark") %>
</td>
</tr>
</table>
<xml id="dso2" src="/Configs/XML_FlowStep.xml"></xml>
<table id="flowtbl" datasrc="#dso2" class="table">
<thead>
<th align="left">
<input input name="chkAll" type="checkbox" id="chkAll" onclick="CheckAll(this.form)"
value="11" />
是否选择行 </th>
<th>
编号
</th>
<th>
名称
</th>
<th>
审核 </th>
</thead>
<tr>
<td>
<input type="checkbox" class="chk1" value="11" />
</td>
<td>
<span datafld="ID"></span>
</td>
<td>
<span datafld="name"></span>
</td>
<td>
<input type="checkbox" class="chk" /><input type="text" />
</td>
</tr>
</table>
<td><input type="button" ID="Button1" text="send" onclick="bianli()" runat="server" />
<input type="text" id="hidvalue" value="" name="Fsname"/>
<table>
<tr>
<td>
<input type="button" class="button" value='关闭' onclick="javascript:window.close()" />
<input type="submit" class="button" value='提交' />
<input type="reset" class="button" value='重置' />
</td>
</tr>
</table>
<br />
</div>
</div>
</div>
</div>
</div>
<!-- 模块 -->
</div>
</form>
</body>
</html>
[/code]
<xml id="dso2" src="/Configs/XML_FlowStep.xml"></xml> <table id="flowtbl" datasrc="#dso2" class="table"> <thead> <th align="left"> <input type="checkbox" class="all" /> 是否选择行 </th> <th> 编号 </th> <th> 名称 </th> <th> 审核 </th> </thead> <tr> <td> <input type="checkbox" class="chk1" value="11" /> </td> <td> <span datafld="ID"></span> </td> <td> <span datafld="name"></span> </td> <td> <input type="checkbox" class="chk" /><input type="text" /> </td> </tr> </table>
<form id="form1" runat="server"> <table id="flowtbl" datasrc="#dso2" class="table"> <thead> <tr jquery1350481007593="6"> <th align="left"> <input class="all" type="checkbox"> 步骤选择 </th> <th> 步骤编号 </th> <th> 步骤名称 </th> <th> 是否审批 </th> </tr> </thead> <tbody> <tr> <td> <input class="chk1" value="11" type="checkbox"> </td> <td> <span datafld="ID">01101</span> </td> <td> <span datafld="name">项目1</span> </td> <td> <input class="chk" type="checkbox" jquery1350481007593="9"><input disabled type="text" jquery1350481007593="8"> </td> </tr> </tbody> <tbody> <tr> <td> <input class="chk1" value="11" type="checkbox"> </td> <td> <span datafld="ID">01102</span> </td> <td> <span datafld="name">项目2</span> </td> <td> <input class="chk" type="checkbox" jquery1350481007593="11"><input disabled type="text" jquery1350481007593="10"> </td> </tr> </tbody> <tbody> <tr> <td> <input class="chk1" value="11" type="checkbox"> </td> <td> <span datafld="ID">02101</span> </td> <td> <span datafld="name">项目3</span> </td> <td> <input class="chk" type="checkbox" jquery1350481007593="13"><input disabled type="text" jquery1350481007593="12"> </td> </tr> </tbody> <tbody> <tr> <td> <input class="chk1" value="11" type="checkbox"> </td> <td> <span datafld="ID">02102</span> </td> <td> <span datafld="name">项目4</span> </td> <td> <input class="chk" type="checkbox" jquery1350481007593="15"><input disabled type="text" jquery1350481007593="14"> </td> </tr> </tbody> <tbody> <tr> <td> <input class="chk1" value="11" type="checkbox"> </td> <td> <span datafld="ID">01103</span> </td> <td> <span datafld="name">项目5</span> </td> <td> <input class="chk" type="checkbox" jquery1350481007593="17"><input disabled type="text" jquery1350481007593="16"> </td> </tr> </tbody> <tbody> <tr> <td> <input class="chk1" value="11" type="checkbox"> </td> <td> <span datafld="ID">01104</span> </td> <td> <span datafld="name">项目6</span> </td> <td> <input class="chk" type="checkbox" jquery1350481007593="19"><input disabled type="text" jquery1350481007593="18"> </td> </tr> </tbody> <tbody> <tr> <td> <input class="chk1" value="11" type="checkbox"> </td> <td> <span datafld="ID">01105</span> </td> <td> <span datafld="name">项目7</span> </td> <td> <input class="chk" type="checkbox" jquery1350481007593="21"><input disabled type="text" jquery1350481007593="20"> </td> </tr> </tbody> <tbody> <tr> <td> <input class="chk1" value="11" type="checkbox"> </td> <td> <span datafld="ID">01106</span> </td> <td> <span datafld="name">项目8</span> </td> <td> <input class="chk" type="checkbox" jquery1350481007593="23"><input disabled type="text" jquery1350481007593="22"> </td> </tr> </tbody> </table> <asp:Button Text="send" OnClientClick="bianli()" runat="server" /> <!-- 这里改成html控件也可以 --> <asp:HiddenField runat="server" ID="hidvalue" /> </form>