0
如何使用jQuery
each()
函數生成<tr>
?使用jQuery生成表格行每個函數
見我嘗試以下:
HTML:
<html>
<table>
<tbody id = "table_tbody">
</tbody>
</table>
</html>
JS:
var tr_count = 10;
var tr_var ="<tr><td><input type = 'text' name= 'name'/></td>t</tr>";
$(tr_count).each(function(){
$(tr_var).appendTo('#table_tbody');
})
這將返回一個<tr>
。
謝謝你,一個簡單的'for'循環做的。只是想知道爲什麼'each()'不起作用? – watkib
'$ .each'遍歷一個集合。查看jQuery文檔和示例以更好地理解。 http://api.jquery.com/jQuery.each/ –
謝謝你會的。 – watkib