I am trying to add rows to the tbody
of a table. But I am having issues with achieving that. Firstly, the function where everything takes place is called on change of a dropdown from a html page. I created a tr
string containing all the td
inside that containing the html elements, text and other stuff. But when I am trying to add that generated row to the table using:
$(newRowContent).appendTo("#tblEntAttributes tbody");
I am encountering an error. The name of the table is tblEntAttributes
and I am trying to add it to the tbody
.
Actually what's happening is jQuery is unable to get tblEntAttributes
as an html element. But I can access it using 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)
似乎不起作用.