数据表错误'执行appendChild()失败'

DataTables error 'Failed to execute appendChild()'

本文关键字:失败 appendChild 数据表 执行 错误      更新时间:2023-09-26
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的onclick函数不在页面上,但在其他地方(做ajax调用)。这可能就是导致错误的原因。我想知道我怎么能保持和修复这个错误的一些方式?

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

<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,并将其更改为最新版本。如果你和我有同样的问题,这个解决方法会对你有帮助。

并确保,数据表需要,jquery.js,而不是jquery.tools.js,如果你使用的是jquery.tools.js,然后更改为jquery.js(最新版本),看看它是否工作。

希望这有帮助,谢谢。