javascript - 数据表错误 'Failed to execute appendChild()'

标签 javascript jquery datatables

Uncaught NotFoundError: Failed to execute 'appendChild' on 'Node': The new child element is null. jquery.tools.min.js:38
f.extend.clean jquery.tools.min.js:38
f.buildFragment jquery.tools.min.js:38
f.fn.extend.domManip jquery.tools.min.js:38
f.fn.extend.append jquery.tools.min.js:37
_fnFeatureHtmlLength jquery.dataTables.js:3209
_fnAddOptionsHtml jquery.dataTables.js:2099
_fnInitialise jquery.dataTables.js:3083
(anonymous function) jquery.dataTables.js:6301
e.extend.each jquery.tools.min.js:36
e.fn.e.each jquery.tools.min.js:36
DataTable jquery.dataTables.js:5838
(anonymous function) index.php?r=rfp:148
n jquery.tools.min.js:36
o.fireWith jquery.tools.min.js:36
e.extend.ready jquery.tools.min.js:36
c.addEventListener.B jquery.tools.min.js:36

一个问题是我将 getElementbyId 用于不在页面上但在其他地方(执行 ajax 调用)的 onclick 函数。这可能是导致错误的原因。我想知道如何保留它并以某种方式修复此错误?

编辑:在下面添加示例代码和一个示例行(有很多)

<table id="main_table" class="dataTable no-footer">
    <thead>
        <tr>
            <td>Stuff</td>
            <td>More Stuff</td>
            <td>Even more stuff</td>
        </tr>
    </thead>

    <tbody>
        <tr role="row">
            <td onclick="document.getElementById("cdid").value=232; document.getElementById("viewForm").submit();"> ... </td>
            <td> more things </td>
            <td> even more things </td>
        </tr>
        ...
        More rows of the same format
    </tbody>

</table>

最佳答案

我在使用 jQuery 数据表时遇到了类似的问题。我通过更改 jQuery 版本以某种方式解决了它。以前,我使用的是 1.6.4 版本的 jQuery

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></script>

但是,后来,我把它改成了最新版本,jquery-1.11.0

<script src="//code.jquery.com/jquery-1.11.0.min.js" type="text/javascript"></script>

错误消失了,我可以看到我的表格。请检查您使用的 jQuery 版本,并将其更改为最新版本。如果您遇到与我相同的问题,此解决方案会有所帮助。

还要确保,dataTables 需要 jquery.js 而不是 jquery.tools.js,如果您使用的是 jquery.tools.js,则将其更改为 jquery.js(最新版本)并查看它是否有效。

希望对您有所帮助, 谢谢。

关于javascript - 数据表错误 'Failed to execute appendChild()',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24017131/

相关文章:

javascript - jquery 解除绑定(bind)事件速度增加

java - Jquery 数据表的 java 包装器的设计模式

javascript - DataTables - 使用单个下拉列表在多列中搜索

javascript - Angular.js 中的过滤指令

javascript - 在保留绑定(bind)的同时连接集合

javascript - 如何检测在 javascript 中按下 x 秒的键?

javascript - jQuery DataTable - 初始化后通过JS转到最后一页

javascript - 如何根据另一个元素的宽度设置一个元素的宽度?

javascript - ES6 promise 执行顺序

javascript - 如何使用 jquery 选择包含精确文本值的范围?