JQuery UI擷取JSON資料,jqueryui擷取json

來源:互聯網
上載者:User

JQuery UI擷取JSON資料,jqueryui擷取json

    最近在學慣用JQuery UI開發一個介面,這是javascript的一個架構,功能強大,介面漂亮。

    首先要下載JQuery UI的包,引入裡面的檔案:

<link href="jquery-ui.css" rel="stylesheet"><script src="external/jquery/jquery.js"></script><script src="jquery-ui.js"></script>
然後是table的設計內容:

<table class="ui-widget ui-widget-content" border="1px"><thead><tr class="ui-widget-header"><td>姓名</td><td>性別</td><td>年齡</td><td>郵箱</td></tr></thead><tbody id="Data"></tbody></table>

tbody用於顯示json資料

另外我們得準備一個json檔案UserInfo.json(和網頁放在同級目錄下),內容如下:

[

{

"name":"王天",

"sex":"男",

"years":"12",

"email":"hello@gmail.com"

},

{

"name":"小文",

"sex":"女",

"years":"21",

"email":"xiaowen@qq.com"

}

]


接下來就是jQuery代碼了:

$(function(){     $("#showDialog").click(function(){          getData();//擷取json資料      });      function getData(){//擷取json資料的函數          $.getJSON("UserInfo.json",function(data){              $("#Data").empty();//先清空tbody              var strHTML = "";              $.each(data,function(InfoIndex,Info){//遍曆json裡的資料                  strHTML += "<tr>";                  strHTML += "<td>"+Info["name"]+"</td>";                  strHTML += "<td>"+Info["sex"]+"</td>";                  strHTML += "<td>"+Info["years"]+"</td>";                  strHTML += "<td>"+Info["email"]+"</td>";                  strHTML += "</tr>";              });              $("#Data").html(strHTML);//顯示到tbody中          });      }

這樣就能擷取json傳過來的資料並展示到前台表格裡了




聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.