我通过使用jQuery创建一个表:添加<tbody>的jQuery冗余<br>
<div class="productlist" style="float:left;" id="productlist">
<script type="text/javascript" language="javascript">
function loadMore() {
var $parent = $("#productlist").empty();
$parent.append('<table id="myTable" cellpadding="0" cellspacing="0" width="100%" class="productlist" style="margin-left:4px; padding-top:2px;"><tbody>');
var $table = $parent.find("#myTable > tbody");
var htmlRow = [
'<tr align="center">',
'<td align="center" id="colunm-product">',
'<br />',
'<div id="brand-item"><a href="#" class="brand_id"><img src="' + value.BrandImage + '" width = "85px"/></a></div>',
'<div id="product_image"><a href="'+'<%: Url.Content("~/") %>' +'Products/ProductSpec/' + value.ID +'?dep='+ value.DepartmentID +'&cat='+value.CategoryID+'&tab=2" style="text-decoration:none"><img src="' + value.PictureName + '" alt="Product" width="135px"/></a></div>',
'</td>',
'</tr>'
];
$table.append(htmlRow.join(''));
$("#myTable > tbody").append('</tbody></table>');
}
</script>
我调用的document.ready功能。但结果在我看来是意外:
<table id="myTable" cellpadding="0" cellspacing="0" width="100%" class="productlist" style="margin-left:4px; padding-top:2px;">
<tbody>
<br/><br/>
<tr> my data </tr>
</tbody></table>
我不知道为什么会出现在表中<br><br>
。如何避免这个问题?
谢谢。
你打算叫'.append我不认为()'不平衡HTML片段。我不确定它是否与您的问题有关,但我会一次添加完整的空表,然后添加行。 – recursive