jQuery .after() 在 IE 中不起作用

发布于 2024-10-14 11:40:15 字数 333 浏览 10 评论 0原文

我正在尝试使用 .after() 将表行添加到表中,但它在任何 IE 中都不起作用,我不断收到此错误 "Object required" 和错误似乎来自我的 jQuery 库中的第 5151 行。

这是我的代码:

$('#view').live('click',function(){
    var parent = $(this).parent();
    parent.after("<tr><td>Test</td></tr>"); 
});

有什么想法吗?

I am trying to add a table row to a table using .after() but it's not working in any IE, I keep getting this error "Object required" and the error seems to be coming from line 5151 in my jQuery library.

Here is my code:

$('#view').live('click',function(){
    var parent = $(this).parent();
    parent.after("<tr><td>Test</td></tr>"); 
});

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

善良天后 2024-10-21 11:40:15

可能的原因是 HTML 代码在没有表格标记的情况下无效。

相反,将元素创建为单独的元素:

parent.after($('<tr/>').append($('<td/>').text('Test')));

A likely reason is that the HTML code isn't valid without a table tag.

Create the elements as separate elements instead:

parent.after($('<tr/>').append($('<td/>').text('Test')));
守护在此方 2024-10-21 11:40:15

我肯定会首先验证你的 HTML;这种事情经常会失败,因为当事情无效时 IE 就不那么“慷慨”。

你知道什么是父母吗?它肯定是tr吗?

I would definitely validate your HTML first; this kind of thing often fails beacuse IE is less "generous" when things aren't valid.

Do you know what parent is? is it definitely a tr?

淡淡離愁欲言轉身 2024-10-21 11:40:15

在 IE、FF 和 Chrome 中运行良好:演示

Works fine for me in IE, FF and Chrome: demo.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文