zoukankan      html  css  js  c++  java
  • 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>

  • 相关阅读:
    apache的日志切割
    实现HTTPS--Apache+Openssl
    CentOS 6.x 编译安装LAMP
    apache的域名跳转
    模型生成过程中检测到一个或多个验证错误
    电商时代已经要过去了。接下来是零售
    电商时代已经要过去了。接下来是零售
    华为手机怎么安装Google
    华为手机怎么安装Google
    table不让td中文字溢出操作方法
  • 原文地址:https://www.cnblogs.com/sode/p/2696736.html
Copyright © 2011-2022 走看看