Anoxia_
2017-08-03 15:03:30
<script?type="text/javascript">
????????????$(document).ready(function(){
????????????????$('#btn').on('click',function(){
????????????????????var?$this?=?$(this)
//??????????????????獲取到按鈕元素賦值給變量
????????????????????$.getJSON('new_file.json',function(data){
//??????????????????用.getJSON()方法獲取到?JSON?內(nèi)的數(shù)組,用data進行操作????
????????????????????????
????????????????????????$this.attr("disabled","true")
//??????????????????禁用元素????使其失去作用
????????????????????$.each(data,?function(index,sport)?{
//??????????????????????遍歷?data?數(shù)組?(index代表數(shù)組下標?sport代表數(shù)組值)
????????????????????????if(index?==?2?){
????????????????????????????$('p').append(sport["name"])
//??????????????????????????找到下標?2??在選中的元素內(nèi)加上?sport.name
????????????????????????}
????????????????????});????
????????????????????})
????????????????})
????????????})
????????</script>
1 回答
已采納

Jerps
TA貢獻3條經(jīng)驗 獲得超0個贊
<script?type="text/javascript"> ????????????$(document).ready(function(){ ????????????????$('#btn').on('click',function(){ ????????????????????var?$this?=?$(this) //??????????????????保存this對象,留備后用,你那解釋也行 ? ????????????????????$.getJSON('new_file.json',function(data){ //??????????????????用.getJSON()方法獲取到?JSON?內(nèi)的數(shù)據(jù),將數(shù)據(jù)(data)傳入function操作? ????????????????????????? ????????????????????????$this.attr("disabled","true") //??????????????????禁用元素????使其失去作用 ????????????????????$.each(data,?function(index,sport)?{ //??????????????????????遍歷?data?數(shù)組?(index代表數(shù)組下標?sport代表數(shù)組值) ????????????????????????if(index?==?2?){ ????????????????????????????$('p').append(sport["name"]) //??????????????????????????找到下標2,在p下添加(綁定)子元素(當前sport數(shù)據(jù)中鍵值對,鍵為name); ????????????????????????} ????????????????????});???? ????????????????????}) ????????????????}) ????????????}) ????????</script>
添加回答
舉報
0/150
提交
取消