jquery和json的一个问题

来源:百度知道 编辑:UC知道 时间:2024/05/30 10:53:57
我现在输出的json是
{"Lottery":[{"lyrq":"09033","lyhm":"7 3 2 4 3 1 2"},{"lyrq":"09034","lyhm":"4 1 7 5 0 6 9"},{"lyrq":"09035","lyhm":"3 5 7 4 8 5 6"}]}
然后
success: function(json)
{//msg为返回的数据,在这里做数据绑定
var Lottery = json.Lottery
for(var i=0;i<Lottery.length;i++){
var row = $("#row").clone();
row.find("#riqi").text(Lottery[i].lyrq);
row.find("#haoma").text(Lottery[i].lyhm);
row.attr("id","ready");//改变绑定好数据的行的id
row.appendTo("#datas");//添加到模板的容器中
}
}

HTML是

<table id="datas" border="1" cellspacing="0" style="border-collapse: collapse">
<tr>
<th style="width:100px;&qu

<script>
var a={"Lottery":[{"lyrq":"09033","lyhm":"7 3 2 4 3 1 2"},{"lyrq":"09034","lyhm":"4 1 7 5 0 6 9"},{"lyrq":"09035","lyhm":"3 5 7 4 8 5 6"}]} ;
alert(a.Lottery.length);
</script>
没错的,注意Json是对象,非字符串。

你可以参考我的代码,这样是没错的。
<table id="datas" border="1" cellspacing="0" style="border-collapse: collapse">
<tr>
<th style="width:100px;" align="center">日期</th>
<th style="width:100px;" align="center">号码</th>
</tr>
<tr id="row" style=" background:#f00; line-height:20px; height:20px; font-size:12px;">
<td id="riqi"></td>
<td id="haoma"></td>
</tr>
</table>
<in