我想使用下面的代碼來動態添加結束標記,然後打開,以便我每三個單元格創建一個新行。幾乎工作,DOM檢查器顯示一個TR節點,問題是,發生了什麼tr tr沒有關閉tr標記。我是Jquery的新手,有什麼我做錯了這個代碼?我可以使用Jquery在動態表內插入一個關閉</tr>標籤和一個開頭<tr>標籤嗎?
<script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.5.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
$('td:nth-child(3n)').after('</tr><tr>');
});
</script>
<table id="mytable" width="266" border="1" cellspacing="10" cellpadding="10">
<tbody>
<tr>
<?php
function somelongassfunction(){
return 'Hello';
}
function have_products($a){
return $a<=20;
}
$x=0;
while (have_products($x)) {
echo '<td>' . somelongassfunction() . '</td>';
$x++;
//-------------------------------------
/*if (fmod($x,3) == 0) {
echo '</tr><tr>';
continue;
}*/
//--------------------------------------
if ($x==20){
break;
}
}
?>
</tr>
</tbody>
</table>
純粹的PHP解決方案不工作? – Michael