html JS.JSON.FetchingData.PopulateTable.ex6

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了html JS.JSON.FetchingData.PopulateTable.ex6相关的知识,希望对你有一定的参考价值。

table {
  width:100%;
  border:1px solid;
  border-collapse: collapse;
}


tr, th, td {
  border:1px solid;
  font-family:courier;
}

td {
  text-align:center;
  padding:10px;
  
}
fieldset {
  padding:10px;
  border-radius:10px;
}

label {
  display:inline-block;
  margin-bottom:10px;
}



#input:invalid {
  background-color:pink;
}

#input:valid {
  background-color:lightgreen;
}
#sub{
  visibility:hidden;
}
var inicio=0;
var final=15;
var users={};
function createTable(users){
  for(var i=0;i<users.data.length;i++){ 
  var givenName=users.data[i][0];
  var proffesion=users.data[i][1];
  var city=users.data[i][2];
  var age=users.data[i][3];
  var dateStart=users.data[i][4];
  var earnings=users.data[i][5];
  var table = document.querySelector("#myTable");
  var row = table.insertRow();
  row.innerHTML = "<td>"+i+"</td><td>"+givenName+"</td><td>"+proffesion+"</td><td>"+city+"</td><td>"+age+"</td><td>"+dateStart+"</td><td>"+earnings+"</td>";
  
  }
  }
function init(){
  search();
  
}
function search() {    
    var queryURL = "https://gist.githubusercontent.com/heiswayi/7fde241975ed8a80535a/raw/ff1caaeaf62bd6740ab7cafcd61f1215de173379/datatables-data.json";
    
    var xhr = new XMLHttpRequest();
    xhr.open('GET', queryURL, true);

    // called when the response is arrived
    xhr.onload = function(e) {
      var jsonResponse = xhr.response;

      // turn the response into a JavaScript object
      users = JSON.parse(jsonResponse);
      createTable(users);
    }
    
    // in case of error
    xhr.onerror = function(err) {
      console.log("Error: " + err);
    }
    
    // sends the request
    xhr.send();
} 
JS.JSON.FetchingData.PopulateTable.ex6
--------------------------------------


A [Pen](https://codepen.io/Onlyforbopi/pen/LgYJjq) by [Pan Doul](https://codepen.io/Onlyforbopi) on [CodePen](https://codepen.io).

[License](https://codepen.io/Onlyforbopi/pen/LgYJjq/license).
<body onload="init();">
<table id="myTable">
 <caption></caption>  
  <tr>
    <th scope="col">ID</th>
    <th scope="col">Name</th>
    <th scope="col">Proffesion</th> 
    <th scope="col">City</th>
    <th scope="col">Age</th>
    <th scope="col">Date of start</th>
    <th scope="col">Earnings</th>
  </tr>
  
</table>
  
    </body>

以上是关于html JS.JSON.FetchingData.PopulateTable.ex6的主要内容,如果未能解决你的问题,请参考以下文章

html JS.JSON.FetchingData.PopulateTable.ex4

html JS.JSON.FetchingData.PopulateTable.ex9

html JS.JSON.FetchingData.PopulateTable.ex8

html JS.JSON.FetchingData.PopulateTable.ex7

html JS.JSON.FetchingData.PopulateTable.ex6

html JS.JSON.FetchingData.PopulateTable.ex5