<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>使用getJSON()方法异步加载JSON格式数据</title>
<script src="http://libs.baidu.com/jquery/1.9.0/jquery.js" type="text/javascript"></script>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="divtest">
<div class="title">
<span class="fl">我最喜欢的一项运动</span>
<span class="fr">
<input id="btnShow" type="button" value="加载" />
</span>
</div>
<ul></ul>
</div>
<script type="text/javascript">
$(function () {
$("#btnShow").bind("click", function () {
var $this = $(this);
$.getJSON('sport.json',function(data){//回调函数
$this.attr("disabled", "true");
$.each(data, function (index, sport) {
$("ul").append("<li>" + sport["name"] + "</li>");
});
});
})
});
</script>
</body>
</html>
下面是sport.json文件里面的东西
[{
{"name" : "足球"},
{"name" : "篮球"},
{"name" : "乒乓球"}
}]
点击加载之后,毫无反应,连
$this.attr("disabled", "true");都没有执行
taba
涂涂023
慕瓜9220888
随时随地看视频慕课网APP
相关分类