• 第十一周作业


    json代码:

    {
      "squadName" : "intriduce the QQ speed",
      "The publishing company" : "Tencent____",
      "data" : 2017,
      "secretBase" : "Super tower",
      "active" : true,
      "members" : [
        {
          "name" : "Personal racing",
          "countDown" : "10",
          "feature" : "gas collection",
          "powers" : [
            "drifting",
            "gas escape",
            "strike"
          ]
        },
        {
         "name" : "team racing",
          "countDown" : "10",
          "feature" : "blue gas collection",
          "powers" : [
            "temp helps",
            "common victory",
            "havae a sense of unity"
          ]
        },
        {
          "name" : "Encounter racing",
          "countDown" : "10",
          "feature" : "Transmission and Acceleration",
          "powers" : [
            "talk with opposite sex",
            "make frieds",
            "may get married"
          ]
        }
      ]
    }
    js代码:
    var header = document.querySelector('header');
    var section = document.querySelector('section');
    var requestURL = 'https://raw.githubusercontent.com/qwe13404033685/qwwert/master/yuan.json';
    var request = new XMLHttpRequest();
    request.open('GET',requestURL);
    request.responseType = 'json';
    request.send();
    request.onload = function() {
      var superHeroes = request.response;
      populateHeader(superHeroes);
      showHeroes(superHeroes);
    }
    function populateHeader(jsonObj) {
      var myH1 = document.createElement('h1');
      myH1.textContent = jsonObj['squadName'];
      header.appendChild(myH1);
      var myPara = document.createElement('p');
      myPara.textContent = 'The publishing company:' + jsonObj['The publishing company'] + ' data: ' + jsonObj['data'];
      header.appendChild(myPara);
    }
    function showHeroes(jsonObj) {
      var heroes = jsonObj['members'];
         
      for (var i = 0; i < heroes.length; i++) {
        var myArticle = document.createElement('article');
        var myH2 = document.createElement('h2');
        var myPara1 = document.createElement('p');
        var myPara2 = document.createElement('p');
        var myPara3 = document.createElement('p');
        var myList = document.createElement('ul');
        myH2.textContent = heroes[i].name;
        myPara1.textContent = 'feature: ' + heroes[i].feature;
        myPara2.textContent = 'count down: ' + heroes[i].countDown;
        myPara3.textContent = 'The racing way';
           
        var superPowers = heroes[i].powers;
        for (var j = 0; j < superPowers.length; j++) {
          var listItem = document.createElement('li');
          listItem.textContent = superPowers[j];
          myList.appendChild(listItem);
        }
        myArticle.appendChild(myH2);
        myArticle.appendChild(myPara1);
        myArticle.appendChild(myPara2);
        myArticle.appendChild(myPara3);
        myArticle.appendChild(myList);
        section.appendChild(myArticle);
      }
    }
    我的json网站为:https://raw.githubusercontent.com/qwe13404033685/qwwert/master/yuan.json
    和老师上课讲的代码其实改变并不大,大致就是把里面的属性和js代码中调用的属性换了一下下


  • 相关阅读:
    yii2权限控制rbac之rule详细讲解
    yii2权限控制rbac之详细操作步骤
    安装 Autoconf, Automake & Libtool
    Linux查看物理CPU个数、核数、逻辑CPU个数
    Nginx端口占用问题
    Druid加密
    Ubuntu16.04安装Zabbix3.2(快速安装教程)
    飞冰ICE
    BeiDou开源项目
    Arthas开源项目
  • 原文地址:https://www.cnblogs.com/yyh187/p/9979723.html
Copyright © 2020-2023  润新知