//1.创建一个元素
var a=document.createElement('a');
//2.给元素添加属性或内容:
a.href='http://www.baidu.com';
a.innerHTML='GO BAIDU';
//3.追加到dom树 父元素.appendChild(子元素);
document.querySelector('div').appendChild(a);
var json='[{"ename":"Tom", "salary":10000, "age":25},{"ename":"John", "salary":11000, "age":28},{"ename":"Mary", "salary":12000, "age":25}]';
var obj=eval(json);
var table=document.createElement('table');
var thead=document.createElement('thead');
var tr=document.createElement('tr');
for(var key in obj[0]){
var th=document.createElement('th');
th.innerHTML=key;
tr.appendChild(th);
}
table.appendChild(thead);
thead.appendChild(tr);
var tbody=document.createElement('tbody');
for(var i=0;i
var tr=document.createElement('tr');
tbody.appendChild(tr);
for(var key in obj[i]){
var td=document.createElement('td');
td.innerHTML=obj[i][key];
tr.appendChild(td);
}
}
table.appendChild(tbody);
document.querySelector('#data').appendChild(table);