Here is my code :
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
; "http://www.w3.org/TR/html4/loose.dtd"><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
</head>
<body>
<div id="divmenutable"></div>
<script type="text/javascript">
$(document).ready(function() 开发者_开发技巧{
var menuTable = $("<table><table>").addClass("table_menu");
var menuRow = $("<tr></tr>");
var menuCol = $("<td>awef</td>");
menuRow.append(menuCol);
menuTable.append(menuRow);
$("#divmenutable").append(menuTable);
});
</script>
</body>
</html>
The result, div add table twice. I dont know why. My real code is to use 'for' loop to add data to table. I have minimized my code to show the problem.
You are creating two tables. Close the end tag.
$('<table><table>').length // 2
Versus
$('<table></table>').length // 1
Could also do
$('<table/>')
精彩评论