简单的 jQuery 片段在 IE 中不起作用
我没有一直使用 jQuery,而是构建了一个 String,然后尝试将其解析为 jQuery。然而,在 IE 上,我收到以下代码片段的奇怪错误消息。它在 Chrome 上运行良好。
$('<tr><td>a</td></tr>');
仅使用此命令会导致 IE 上出现以下错误消息:
Object doesn't support this property or method 'getElementsByTagName'
这是怎么回事?在 Chrome 中,就像我说的,它工作得很好,正如我所期望的那样,但 IE 拒绝理解它。
任何线索将不胜感激。
编辑:即使失败,只有我遇到这个问题吗?
$('<td>a</td>');
Instead of using jQuery all the time, I instead built a String
and then tried to parse it to jQuery. However, on IE I got a weird error message for the following snippet. It works fine on Chrome.
$('<tr><td>a</td></tr>');
Using just this results in the following error message on IE:
Object doesn't support this property or method 'getElementsByTagName'
What's going on here? In Chrome, like I said, it works blissfully and just as I would expect, but IE refuses to understand it.
Any clues would be greatly appreciated.
Edit: Even this fails, is it just me having this problem?
$('<td>a</td>');
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
也许 IE 正在寻找顶级
。 ...
包围 tr 和 td?
Perhaps IE is looking for a top level
<table> ... </table>
to surround the tr and td?您可以从
和
.append('
...
')
开始,或者如果它仍然是空的,使用.html('
...
')
来填充它。You could start with a
<table>
and.append('<tr>...</tr>')
to it, or if it's still empty, use.html('<tr>...</tr>')
to fill it.IE8以下对TD和TR元素非常讲究。我不相信您可以在没有父表元素的情况下创建包含这些类型元素的文档片段(这就是您正在做的事情)。
IE8 and under are very particular about TD and TR elements. I do not believe you can create a document fragment (which is what you are doing) containing these types of elements without a parent table element.