gpt4 book ai didi

jQuery 关闭打开标签

转载 作者:行者123 更新时间:2023-11-28 05:07:45 25 4
gpt4 key购买 nike

在尝试将 xml 文件解析为表格格式时,jQuery 一直关闭我的开口 <tr>标签。有解决办法吗?

<script type="text/javascript">
$(document).ready(function(){
$.ajax({
type: "GET",
url: "sample-data.xml",
dataType: "xml",
success: parseXml
});
});

function parseXml(xml)
{
$(xml).find("user").each(function()
{
var id = "#sortable";
$(id).append("<tr>");
$(id).append("<td>" + $(this).find("name").text() + "</td>");
$(id).append("</tr>");

});
}
</script>

<table id="table" class="tablesorter">
<thead>
<tr>
<th>test</th>
</tr>
</thead>
<tbody id="sortable">

</tbody>
</table>

这是标记的输出方式:

 <tr></tr>
<td>data</td>

最佳答案

只需调用 1 个追加而不是多个追加。

改变这部分:

        $(id).append("<tr>");
$(id).append("<td>" + $(this).find("name").text() + "</td>");
$(id).append("</tr>");

为此:

        $(id).append("<tr><td>" + $(this).find("name").text() + "</td></tr>");

关于jQuery 关闭打开标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4965201/

25 4 0