61,653
社区成员




<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>dddd</title>
<script src="jquery-1.8.0.min.js" type="text/javascript"></script>
<script type="text/javascript">
function AddRows() {
//测试数据,你从哪里得到都是可以的,这里只是示例
arr = [{ "Goods_id": "66", "Goods_name": "AAA" }, { "Goods_id": "6", "Goods_name": "BBB" }, { "Goods_id": "3", "Goods_name": "CCC"}];
$(arr).each(function (index,k) {
$("#content_body").append("<tr><td style='border-left:1px solid #cccccc'><input type='checkbox' id='ID" + k["Goods_id"] + "' /></td><td>" + k["Goods_id"] + "</td><td><input id='Name" + k["Goods_id"] + "'/></td><td>" + k["Goods_name"] + "</td></tr>");
});
}
function GetData() {
txtdata = [];
id = [];
chkbox = [];
$("#content_body tr").each(function (index, k) {
chk = $(k).find("input[type='checkbox']");
rowId = chk.attr("id").substr(2);
id.push(rowId);
if (chk.attr("checked")) {
chkbox.push('"checkbox' + rowId + '":"' + rowId + '"');
}
txtdata.push('"name' + rowId + '":"' + $("#Name" + rowId).val() + '"');
});
data = '{"id":"' + id + '",' + txtdata + ',' + chkbox + '}';
$.ajax({ url: 'getData.aspx',
type: 'post',
data: $.parseJSON(data),
success: function (result) { alert(result); }
});
}
</script>
</head>
<body>
<form id="form1" runat="server">
<table id="content_body">
</table>
<input type="button" value="生成表格" onclick="AddRows()" />
<input type="button" value="得到数据" onclick="GetData()" />
</form>
</body>
</html>
<%@ Page Language="C#" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
String[] id = Request.Form["id"].Split(',');
Response.Write("你输入的内容:\r\n");
for (int i = 0; i < id.Length; i++)
{
Response.Write("得到选中的Id=:"+ Request.Form["checkbox" + id[i]] +"\r\n");
Response.Write("得到输入的内容:" + Request.Form["name" + id[i]] + "\r\n");
}
}
</script>