不太理解 $.getJSON("http://www.xianlaiwan.cn/data/sport.json",function(data),http://www.xianlaiwan.cn/data/sport.json是從哪來的?function(data)為什么要傳個data,還有 $.each(data, function (index, sport) { ...}這個函數是什么意思?不懂的比較多,求耐心指教~~~謝謝
? ?
? ? ? ? <script type="text/javascript">
? ? ? ? ? ? $(function () {
? ? ? ? ? ? ? ? $("#btnShow").bind("click", function () {
? ? ? ? ? ? ? ? ? ? var $this = $(this);
? ? ? ? ? ? ? ? ? ? $.getJSON("http://www.xianlaiwan.cn/data/sport.json",function(data){
? ? ? ? ? ? ? ? ? ? ? ? $this.attr("disabled", "true");
? ? ? ? ? ? ? ? ? ? ? ? $.each(data, function (index, sport) {
? ? ? ? ? ? ? ? ? ? ? ? ? ? if(index==3)
? ? ? ? ? ? ? ? ? ? ? ? ? ? $("ul").append("<li>" + sport["name"] + "</li>");
? ? ? ? ? ? ? ? ? ? ? ? });
? ??
? ? ? ? ? ? ? ? ? ? });
? ? ? ? ? ? ? ? })
? ? ? ? ? ? });
? ? ? ? </script>
2016-03-15
data存放的是訪問http://www.xianlaiwan.cn/data/sport.json后傳回來的數據。
$.each(data, function (index, sport) { ...}
是遍歷data字符串。 ? 應為data是json類型的。