【发布时间】:2020-09-06 20:29:15
【问题描述】:
我有一个带有 id="result" 的 div,我想在这个 div 标记中显示我的数据。
如何追加此表数据。
我不明白table data tag table is in the string 所以它是如何工作的
function displayAddress() {
if (flag == 0) {
tabledata = "<table style='position: fixed; background-color:lightgrey; border: 1px solid black; border-collapse: collapse; margin-top: 25px;' border = '1'><tr><th>Name</th><th>Type</th><th>Address</th><th>Email</th><th>Mobile</th><th>Location</th></tr>";
}
for (i = 0; i < dataArray.length; i++) {
var tempname = dataArray[i].Name;
var temptype = dataArray[i].Type;
var tempaddress = dataArray[i].Address;
var tempemail = dataArray[i].Email;
var tempmobile = dataArray[i].Mobile;
var templocation = dataArray[i].Location;
//Please fill the required code to store the values in tabledata.
}
console.log(tabledata);
if (flag == 0) {
//Please fill the required code to store the table data in result.
document.getElementById("name").value = "";
document.getElementsByName("type").checked = false;
document.getElementById("address").value = "";
document.getElementById("email").value = "";
document.getElementById("mobile").value = "";
document.getElementById("location").value = "";
}
count = 0;
}
【问题讨论】:
-
我给你做了一个sn-p。请为minimal reproducible example添加相关数据和HTML
-
你有
tabledata但你对那个变量什么也不做。我希望您想将tabledata中的 HTML 添加到 ID 为result的 div 中?如果是这样Inserting HTML into a div
标签: javascript html arrays