在尝试将 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>