jquery - append 到表时无法读取 null 的属性 'childNodes'

标签 jquery html-table append

我想这将是我得到的一个非常明显的答案,但我自己真的找不到。

这是我的表格(我省去了所有的 tds)

<table id="COA_Table">
    <thead>
        <tr>some th</tr>
    </thead>
    <tbody>
        <tr>some TD</tr>
    </tbody>
</table>

这是我的 jQuery 代码:

$(document).ready(function () {
    console.log("ready!");

    $('#COA_Table > tbody:last').append('<tr><td><input type=\"checkbox\"></td><td></td>New account<td></td><td></td></tr>');
})

最后,我得到的错误代码:

Uncaught TypeError: Cannot read property 'childNodes' of null

这让我发疯

最佳答案

请注意,您的结构中有错误

<td></td>New account<td></td>

此文本未放置在任何地方,可能会导致完整代码中出现错误。

应该是这样

<td></td><td>New account</td>

Demo With These Edits

关于jquery - append 到表时无法读取 null 的属性 'childNodes',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17305240/

相关文章:

javascript - Slick Slider slickGoTo 方法打破轮播

html - .mainTable TD CSS 在 chrome 中不起作用

javascript - 我怎样才能让表格的主体滚动但将其头部固定在原位?

jquery - 在 jQuery 中,如何将特定的通配符字符串保存到变量中?

javascript - jQuery 克隆元素仅在循环内 append 一次克隆项

jQuery ID 选择器不适用于 IE7 (.show()/.hide())

javascript - 滚动到 jquery 数组中的下一个元素

html - 高级 css/html 表格样式

javascript - AngularJS - 如何将 json append 到另一个 json 对象?

javascript - 如何动画列表?