【发布时间】:2016-06-30 17:33:53
【问题描述】:
查看问题代码中的注释:
用jQuery从JSON对象动态创建的tr对象不能被使用两次追加到不同的表中?
function myfunc(obj)
{
//obj is JSON object
jQuery('#ClientInfo').html('');
jQuery('#clientListTable2G').html('');
jQuery.each(obj, function( key, objClient ) {
var tr = jQuery('<tr>').append(
jQuery('<td>').text(objClient.hostname),
jQuery('<td>').text(objClient.mac),
jQuery('<td>').text(objClient.rssi),
jQuery('<td>').text("Wifi 2.4G"),
jQuery('<td>').text(objClient.ip)
).appendTo('#ClientInfo');
/* HERE IS THE QUESTION */
//If i uncomment below line than the #ClientInfo becomes blank and the tr row fills in #clientListTable2G only
//jQuery('#clientListTable2G').append(jQuery(tr));
});
}
【问题讨论】:
-
结束的tr在哪里???
-
我不确定此语法中是否需要结束标记。但如果仅附加在一个表中,则可以使用。
标签: jquery object dynamic html-table row