小弟碰见个问题。急待解决!求jquery,js高人!!!
发布网友
发布时间:2022-09-21 22:27
我来回答
共2个回答
热心网友
时间:2023-11-22 06:18
不用那么复杂,数组中加对象直接加就行。如下
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<script language="javascript" src="/js/jquery-1.4.4.js" type="text/javascript"></script>
<script>
$(document).ready(function(){
$("#s").click(function(){
var data = {};
var recordList = [];
$("input:checked").each(function(){
var lotteryId = $(this).val();
var bgIssue = $(this).parent().siblings('td:eq(0)').children().val();//获取该行开始期号
var endIssue = $(this).parent().siblings('td:eq(1)').children().val();//获取该行开始期号
recordList.push({"lotteryId":lotteryId, "bgIssue":bgIssue, "endIssue":endIssue});
});
alert(recordList[1].lotteryId);
var channelName = $("#channName").val();
data["channSales.channelName"] = channelName;
data["channSales.recordList"] = recordList;
alert(data["channSales.recordList"][0].bgIssue);
});
});
</script>
<body>
<input type="text" id="channName" name="channName" value="channName" />
<table width="200" border="1">
<tr>
<td><input type="text" name="bgIssue" value="11" /></td>
<td><input type="text" name="endIssue" value="12" /></td>
<td><input type="checkbox" name="c" value="c1" /></td>
<td> </td>
</tr>
<tr>
<td><input type="text" name="bgIssue" value="21" /></td>
<td><input type="text" name="endIssue" value="22" /></td>
<td><input type="checkbox" name="c" value="c2" /></td>
<td> </td>
</tr>
</table>
<input type="button" id="s" value="button" />
</body>
</html>
热心网友
时间:2023-11-22 06:19
你把data定义错了,var data={"channName":"","recordList":[]};不就直接是你要的数据吗,干嘛要定义成数组呢???