【发布时间】:2012-06-06 18:26:36
【问题描述】:
我正在尝试向表的tbody 添加行。但我在实现这一目标方面遇到了问题。首先,在从 html 页面更改下拉菜单时调用发生所有事情的函数。我创建了一个tr 字符串,其中包含所有td,其中包含html 元素、文本和其他内容。但是当我尝试使用以下方法将生成的行添加到表中时:
$(newRowContent).appendTo("#tblEntAttributes tbody");
我遇到了一个错误。表的名称是tblEntAttributes,我正在尝试将其添加到tbody。
实际上,jQuery 无法将 tblEntAttributes 作为 html 元素。但我可以使用documemt.getElementById("tblEntAttributes"); 访问它
有什么方法可以通过向表的tbody 添加行来实现这一点。也许是旁路之类的。
这是完整的代码:
var newRowContent = "<tr><td><input type=\"checkbox\" id=\"" + chkboxId + "\" value=\"" + chkboxValue + "\"></td><td>" + displayName + "</td><td>" + logicalName + "</td><td>" + dataType + "</td><td><input type=\"checkbox\" id=\"chkAllPrimaryAttrs\" name=\"chkAllPrimaryAttrs\" value=\"chkAllPrimaryAttrs\"></td><td><input type=\"checkbox\" id=\"chkAllPrimaryAttrs\" name=\"chkAllPrimaryAttrs\" value=\"chkAllPrimaryAttrs\"></td></tr>";
$("#tblEntAttributes tbody").append(newRowContent);
我忘了提一件事,这段代码所写的函数实际上是 ajax 调用的成功回调函数。我可以使用document.getElementById("tblEntAttributes") 访问该表,但由于某种原因$(#tblEntAttributes) 似乎不起作用。
【问题讨论】:
-
你能发布一些你的DOM的sn-p(主要是有问题的表)
-
$('#Table1 > tbody') 取自stackoverflow.com/questions/6763006/…
标签: jquery dynamic html-table rows