<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>挑战题</title> </head> <body> <div><input id="btnShow" type="button" value="加载学生信息"/></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>分数:"+sport.score+"</li>") }) }) </script> </body> </html>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>挑战题</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="加载学生信息"/></div>
<ul></ul>
<script type="text/javascript">
//用JSON语法定义对象source
var source={name:'kayber',
age:'18',
sex:'male',
score:'100'};
//文档加载完毕执行
$(function(){
$("#btnShow").bind("click",function(){
//定义一个数组,取出JSON对象数据
var arr=new Array();
$.each(source,function(index,sport){
//将遍历数据放入数组
arr[index]=sport;
});//each结束
//将数组内容放入文档
$("ul").append("<li>姓名:"+arr['name']+"</li><li>年龄:"+arr['age']+"</li><li>性别:"+arr['sex']+"</li><li>分数:"+arr['score']+"</li>");
});//bind结束
});//$()结束
</script>
</body>
</html>
错的太多,等我给你改一下
<script src="http://libs.baidu.com/jquery/1.8.2/jquery.js" type="text/javascript"></script>
放入head里面
没有引入jquery,^_^