动态追加表行时,列切换不起作用

Column toggle not working when append the table rows dynamically

本文关键字:不起作用 追加 动态      更新时间:2023-09-28

在jQuery mobile v 1.4.5中,我使用了带有列切换的表行动态追加,但它不适用于动态生成的行。

<table id="tab" data-role="table" data-mode="columntoggle" class="ui-responsive">
    <tbody id="tb" >
        <thead id="th">
            <tr id="tr1">
                <th>First</th>
                <th data-priority="1">Second</th>
                <th data-priority="2">third</th>
            </tr>
        </thead>
    </tbody>
    </table>

这是我试过的Fiddle。

我参考了这份jQuery移动文档。

注意:我想在前几行的顶部插入表行(动态添加的行是我使用"after"属性的原因)。

编辑:

新链接如下所示,用于定位表顶部创建的新行

http://jsfiddle.net/txej8qhj/6/


以下链接运行良好;

http://jsfiddle.net/txej8qhj/3/

也许你也知道。有时我们可能会忽略一些事情。应该将theadtbody元素分开。实际上,thead元素首先出现在如下表中;

<table>
    <thead>
    </thead>
    <tbody>
    </tbody>
</table>

检查以下链接以用作指南;

http://demos.jquerymobile.com/1.4.5/table-column-toggle/#&ui state=对话框

您需要调用刷新并触发在table元素上创建函数。

请尝试以下操作:

 $("#tr1").after(newrow);
 $('#tab').table("refresh").trigger("create");