写进去代码点按钮也没用,上一节的内容也是。
在if (index==3)之后加上大括号
我用的火狐浏览器,你可以尝试换换浏览器哦。
<!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>
<title>使用getJSON()方法异步加载JSON格式数据</title>
<script src="https://libs.baidu.com/jquery/1.9.0/jquery.js" type="text/javascript"></script> //注意:路径写https:
<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("https://www.imooc.com/data/sport.json", function (data) { //注意:粘贴这块代码试试
$this.attr("disabled", "true");
$.each(data, function (index, sport) {
if(index==3)
$("ul").append("<li>" + sport["name"] + "</li>");
});
});
})
});
</script>
</body>
</html>可复制,可用。希望对你有帮助吧 (●'◡'●)
免费的果然差
没反应是因为url的不确定是否正确,自己在本地写的可以
我是在Hbuiler里面重新写了一遍 没问题 在这里没反应
把页面中的两个http都改成https
我也是