js前端获取表格中的数据生成对应的json数组?急!!

城池523 2013-11-29 02:38:08
html中的数据:
<div id="kysite_listcontent">
<table cellspacing=1 cellpadding=1 align=center border=0>
<tbody>
<tr>
<td><a title=广州市-白云区 href="http://xxx.com" target=_blank>白云1</a></td>
</tr>
<tr>
<td><a title=深圳市-宝安区 href="http://xxx.com" target=_blank>宝安1</a></td>
</tr>
<tr>
<td><a title=深圳市-宝安区 href="http://xxx.com" target=_blank>宝安2</a></td>
</tr>
<tr>
<td><a title=深圳市-宝安区 href="http://xxx.com" target=_blank>宝安3</a></td>
</tr>
<tr>
<td><a title=深圳市-宝安区 href="http://xxx.com" target=_blank>宝安4</a></td>
</tr>
<tr>
<td><a title=深圳市-南山区 href="http://xxx.com" target=_blank>南山1</a></td>
</tr>
<tr>
<td><a title=深圳市-福田区 href="http://xxx.com" target=_blank>福田1</a></td>
</tr>
<tr>
<td><a title=深圳市-龙岗区 href="http://xxx.com" target=_blank>龙岗</a></td>
</tr>
<tr>
<td><a title=深圳市-龙岗区 href="http://xxx.com" target=_blank>龙岗</A></td>
</tr>
<tr>
<td><a title=上海-浦东新区 href="http://xxx.com" target=_blank>浦东</a></td>
</tr>
<tr>
<td><a title=深圳市-宝安区 href="http://xxx.com" target=_blank>宝安</a></td>
</tr>
<tr>
<td><a title=深圳市-南山区 href="http://xxx.com" target=_blank>南山</a></td>
</tr>
<tr>
<td><a title="" href="http://xxx.com" target=_blank>福田</a></td>
</tr>
<tr></tr>
</tbody>
</table>
</div>
想要生成类似的json数组:
var arrObj=[
{title:"深圳",info:[
{quyu:"宝安区",wd:["宝安1|http://xxx.com","宝安2|http://xxx.com","宝安3|http://xxx.com","宝安4|http://xxx.com","宝安5|http://xxx.com","宝安6|http://xxx.com"]},{quyu:"南山区",wd:["南山1|http://xxx.com","南山2|http://xxx.com","南山3|http://xxx.com"]}
,{quyu:"福田区",wd:["福田1|http://xxx.com","福田2|http://xxx.com","福田3|http://xxx.com"]}
]
},
{title:"上海",info:[
{quyu:"浦东新区1",wd:["浦东1|http://xxx.com","浦东2|http://xxx.com","浦东3|http://xxx.com"]},{quyu:"浦东新区2",wd:["浦东4|http://xxx.com","浦东5|http://xxx.com","浦东6|http://xxx.com"]}
,{quyu:"浦东新区3",wd:["福田7|http://xxx.com","福田8|http://xxx.com","福田9|http://xxx.com"]}
]
},
{title:"广州",info:[
{quyu:"白云区1",wd:["白云1|http://xxx.com","白云2|http://xxx.com","白云3|http://xxx.com"]},{quyu:"白云区2",wd:["白云4|http://xxx.com","白云5|http://xxx.com","白云6|http://xxx.com"]}
,{quyu:"白云区3",wd:["白云7|http://xxx.com","白云8|http://xxx.com","白云9|http://xxx.com"]}
]
}
];

我要展示到页面上显示为:
...全文
313 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
snjcaorui 2013-11-29
  • 打赏
  • 举报
回复
$(function () { var Citys = []; $.each($('table tr td a'), function (i, d) { var citys = this.title.split('-'); Citys[Citys.length] = { 'prove': citys[0], 'city': citys[1], 'href': this.href, 'name': this.innerText }; }) $.each(Citys, function (i, d) { //这里写你想要的 }) })

87,996

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧