gpt4 book ai didi

javascript - 修复不正确的嵌套

转载 作者:太空宇宙 更新时间:2023-11-04 05:33:07 24 4
gpt4 key购买 nike

function drawinventoryList() {
inventoryArray.sort();
var inventoryString = "";
for (x in inventoryArray) {
arrayValue = inventoryArray[x];
var counter = parseInt(x) + 1;
if (counter == 1) {
inventoryString = "<table width='100%' celpadding='0' cellspacing='0' style='border:1px solid #d00;'>"
}
if (arrayValue.substring(0, arrayValue.indexOf("@")) != "XXXXXXXX") {
inventoryString = inventoryString + "<tr><td>" + counter + ". " + arrayValue.substring(0, arrayValue.indexOf("@")) + ", " + arrayValue.substring(arrayValue.indexOf("@") + 1) + " (<a href=\"javascript:removeinventory('" + x + "')\">remove</a>)</td></tr>";
}
}
if (inventoryString == "") inventoryString = "None."
document.getElementById("selectedInventories").innerHTML = inventoryString;
}

...这个函数创建了一个无效的表。我需要在单独的列中显示“计数器”、“名称”和“删除链接”。如何正确创建和关闭所有标签?

非常感谢

最佳答案

看起来您只是忘记了表格的结束标记。试试这个:

function drawinventoryList() {
inventoryArray.sort();
var inventoryString = "";
for (x in inventoryArray) {
arrayValue = inventoryArray[x];
var counter = parseInt(x) + 1;
if (counter == 1) {
inventoryString = "<table width='100%' celpadding='0' cellspacing='0' style='border:1px solid #d00;'>"
}
if (arrayValue.substring(0, arrayValue.indexOf("@")) != "XXXXXXXX") {
inventoryString = inventoryString + "<tr><td>" + counter + ". " + arrayValue.substring(0, arrayValue.indexOf("@")) + ", " + arrayValue.substring(arrayValue.indexOf("@") + 1) + " (<a href=\"javascript:removeinventory('" + x + "')\">remove</a>)</td></tr>";
}
}
if (inventoryString == "") {
inventoryString = "None.";
} else {
inventoryString = inventoryString + "</table>";
}
document.getElementById("selectedInventories").innerHTML = inventoryString;
}

唯一的变化来自:

if (inventoryString == "") inventoryString = "None."

到:

    if (inventoryString == "") {
inventoryString = "None.";
} else {
inventoryString = inventoryString + "</table>";
}

更新:在您的评论中,您声明

I still need to separate counter, name and link in separated [sic] TD

这可能只是插入一些 </td><td> 的问题部分,例如:

inventoryString = inventoryString +
"<tr>" +
"<td>" + counter + ".</td>" +
"<td>" + arrayValue.substring(0, arrayValue.indexOf("@")) + ", " +
arrayValue.substring(arrayValue.indexOf("@") + 1) + "</td>" +
"<td>(<a href=\"javascript:removeinventory('" + x +
"')\">remove</a>)</td>" +
"</tr>";

关于javascript - 修复不正确的嵌套,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1956659/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com