jquery json 结合

引用:http://www.codefans.net/jscss/code/3575.shtml

<!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=utf-8" />
<title>jQuery与Json结合的一个应用例子</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
var data = {
"siteData" : [

{
"siteClass" : "网页制作",
"siteList" : [
{"sName" : "蓝色理想", "url" : "http://www.blueidea.com/"},
{"sName" : "51CTO", "url" : "http://www.blueidea.com/"},
{"sName" : "博客园", "url" : "http://www.cnblogs.com/"}
]
},

{
"siteClass" : "在线音乐",
"siteList" : [
{"sName" : "百度MP3", "url" : "http://mp3.baidu.com/"},
{"sName" : "千千静听", "url" : "http://www.music2.com/"},
{"sName" : "酷狗音乐", "url" : "http://www.kugou.com/"}
]
},

{
"siteClass" : "求职招聘",
"siteList" : [
{"sName" : "58同城", "url" : "http://www.58.com/"},
{"sName" : "赶集网", "url" : "http://www.ganji.com/"}
]
}

]
}
var items = [];
$.each(data.siteData, function(i, val) {
var li2Size = val.siteList.length;
for(var m=0, li2 = ''; m < li2Size; m++){
li2 += '<li id="li_'+i+'_'+m+'"><a href="' + val.siteList[m].url + '" title="' + val.siteList[m].sName + '" target="_blank">' + val.siteList[m].sName + '</a></li>';
}
items.push('<li><dl id="li_' + i + '"><dt>' + val.siteClass +'</dt><dd><ul>'+ li2 + '</ul></dd></dl></li>');
});

$('<ul/>', {
'style': 'color:red;',
'class': 'my-new-list',
html: items.join('')
}).appendTo('body');
})
</script>
</head>
<body>
</body>
</html>

posted @ 2012-09-21 13:00  镇水古月  阅读(162)  评论(0编辑  收藏  举报