在运行时使用jquery准备表体会导致设计问题

Table body preparation using jquery in run time is causing design issue

本文关键字:体会 问题 运行时 jquery      更新时间:2023-09-26

表格行和数据没有以正确的格式形成

这是问题的链接

http://jsfiddle.net/otc056L9/

下面是HTML代码

<table border="1" style="width: 100%" class="eventtable">
    <thead style="color: blue">
        <tr>
            <th>#</th>
            <th>Field Name</th>
        </tr>
    </thead>
    <tbody id="tblEntity"></tbody>
</table>

您将td和输入(以及figure.text)都附加到tr,因为tr.append("<td>")会再次返回tr以获得可链接性。

正确的代码可能是这样的:

// Adding the input into the row
tr.append("<td>").find('td').append(input);
// Your text
tr.append("<td>").find('td').append(Column.figure.text);

演示:http://jsfiddle.net/otc056L9/1/

或者您可以使用$.fn.appendTo方法,如下所示:

$("<td>").appendTo(tr).append(input);