为什么 jQuery .html() 方法不能在 IE8 中使用自定义标签?

发布于 2024-08-25 14:50:28 字数 310 浏览 4 评论 0原文

我有以下 html 代码:

<mytag>
      Just Some Text
</mytag> 

我有这个 jQuery 命令

$('mytag').each(function () { alert($(this).html()); });

在除 IE 之外的所有浏览器中我都得到了内部 HTML,在 IE 中我没有。任何人都可以解开这个谜团吗?我已经用 IE8、Mozilla、Opera、Chrome 和 Safari 对此进行了测试

I have the following html code:

<mytag>
      Just Some Text
</mytag> 

And I have this jQuery command

$('mytag').each(function () { alert($(this).html()); });

In all browsers except IE I'm getting the inner HTML, in IE I'm not. Anyone can shed any light on this mystery? I've tested this with IE8, Mozilla, Opera, Chrome and Safari

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

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

发布评论

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

评论(2

如梦 2024-09-01 14:50:28

因为 Internet Explorer 不会像您测试代码的其他浏览器那样对特定类型的无效 HTML 进行纠错

我想你可以用以下方法绕过它(它适用于应用 CSS):

document.createElement('mytag')

...但是你最好编写 HTML(或编写 XML 并将其作为 application/xml 提供)。

Because Internet Explorer doesn't error correct for that particular type of invalid HTML in the same way that the other browsers you have tested the code with do.

I would imagine that you can hack around it (it works for applying CSS) with:

document.createElement('mytag')

… but you would be better off writing HTML (or writing XML and serving it as application/xml).

抱着落日 2024-09-01 14:50:28

对于 IE,您需要将其放入标签中 -> xmlns='mytag'

<mytag xmlns='mytag'>
  Just Some Text
</mytag>

现在 IE 和所有其他浏览器都可以“看到”您的标记

For IE, you need put this in your tag -> xmlns='mytag'

<mytag xmlns='mytag'>
  Just Some Text
</mytag>

now IE and all other browsers can "see" your tag

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