<!DOCTYPE?html>
<html>
????<head>
????????<meta?http-equiv="Content-Type"?content="text/html;?charset=utf-8"?/>
????????<title>挑戰(zhàn)題</title>
????</head>
????<body>
????????<div><input?id="btnShow"?type="button"?value="加載學(xué)生信息"/></div>
????????<ul></ul>
????????<script>
????????????var?source=[{'name':'kayber'},
????????????????????????{'age':'18'},
????????????????????????{'sex':'male'},
????????????????????????{'score':'100'}
???????????????????????];
????????????$("#btnShow").bind("click",function(){
????????????????$.each(source,function(index,sport){
????????????????????$("ul").append("<li>姓名:"+sport.name+"</li><li>年齡:"+sport.age+"</li><li>性別:"+sport.sex+"</li><li>分?jǐn)?shù):"+sport.score+"</li>")
????????????????})
????????????})
????????????
????????</script>
????????
????</body>
</html>
2017-08-04
<!DOCTYPE html>
<html>
??? <head>
??????? <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
??????? <title>挑戰(zhàn)題</title>
??????? <script src="http://libs.baidu.com/jquery/1.8.2/jquery.js" type="text/javascript"></script>
??? </head>
??? <body>
??????? <div><input id="btnShow" type="button" value="加載學(xué)生信息"/></div>
??????? <ul></ul>
??????? <script type="text/javascript">
?? ??? ?//用JSON語(yǔ)法定義對(duì)象source
??????????? var source={name:'kayber',
??????????????????????? age:'18',
??????????????????????? sex:'male',
??????????????????????? score:'100'};
?? ??? ?//文檔加載完畢執(zhí)行
?? ?$(function(){
??????????? $("#btnShow").bind("click",function(){
?? ??? ??? ??? ?//定義一個(gè)數(shù)組,取出JSON對(duì)象數(shù)據(jù)
?? ??? ??? ??? ?var arr=new Array();
??????????????? $.each(source,function(index,sport){
?? ??? ??? ??? ??? ?//將遍歷數(shù)據(jù)放入數(shù)組
?? ??? ??? ??? ??? ?arr[index]=sport;
?????????????????? ?
??????????????? });//each結(jié)束
?? ??? ??? ??? ?//將數(shù)組內(nèi)容放入文檔
?? ??? ??? ??? ?$("ul").append("<li>姓名:"+arr['name']+"</li><li>年齡:"+arr['age']+"</li><li>性別:"+arr['sex']+"</li><li>分?jǐn)?shù):"+arr['score']+"</li>");
??????????? });//bind結(jié)束
?? ??? ??? ??? ??? ??? ?});//$()結(jié)束
??????????? ?
??????? </script>
??????? ?
??? </body>
</html>
2017-08-04
錯(cuò)的太多,等我給你改一下
2017-08-04
<script src="http://libs.baidu.com/jquery/1.8.2/jquery.js" type="text/javascript"></script>
放入head里面
2017-08-04
沒(méi)有引入jquery,^_^