我需要创建一个动态加载的表。该表应附加到div标签。我需要在jquery中完成这个。表值应根据服务器的输出动态给出。
var Obj = JSON.parse(response.getReturnValue());// My parsed json output
我需要显示类似
的内容 <div id= "er"></div>
<table><tr><td> Value : Obj.ab</td> <td> Value : Obj.cd </td?</tr></table>
将表附加到div标签,然后使用jquery
动态显示输出我需要使用jquery完成所有这些。 它有什么解决方案吗?
答案 0 :(得分:0)
在这里你去!
<div id="data">
</div>
var div = document.getElementById("data");
var dataObj = {
name:"XYZ",
education:"B.Tech",
country:"ABC"
};
var table = document.createElement('table');
var thead = document.createElement('thead');
var thName = document.createElement('th');
var thCountry = document.createElement('th');
var thEducation = document.createElement('th');
thName.innerHTML = "Name";
thEducation.innerHTML = "Education";
thCountry.innerHTML = "Country"
thead.appendChild(thName);
thead.appendChild(thEducation)
thead.appendChild(thCountry)
var tr = document.createElement('tr');
var tdName = document.createElement('td');
var tdEducation = document.createElement('td');
var tdCountry = document.createElement('td');
tdName.innerHTML = dataObj.name;
tdEducation.innerHTML = dataObj.education;
tdCountry.innerHTML = dataObj.country;
tr.appendChild(tdName);
tr.appendChild(tdEducation);
tr.appendChild(tdCountry);
table.appendChild(thead);
table.appendChild(tr);
div.appendChild(table);