无法识别克隆的父元素中的IE8 HTML5元素(IE8 HTML5 elements within cloned parent elements are not recognised)

编程入门 行业动态 更新时间:2024-10-12 12:23:02
无法识别克隆的父元素中的IE8 HTML5元素(IE8 HTML5 elements within cloned parent elements are not recognised)

我正在使用html5shiv为HTML5元素启用样式。

当我克隆具有HTML5元素子元素的非HTML5元素(并且只有非HTML5元素)时,IE8无法识别该子元素。

在以下示例中,第一部分是粉红色,而克隆版本则不是。

<!doctype html> <html> <head> <style> div section { background:#f0f; display:block; } </style> <script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.2/html5shiv.min.js"></script> <script src="//code.jquery.com/jquery-1.11.1.min.js"></script> <script> jQuery(function ($) { $('#article').append($('div').clone()); }); </script> </head> <body> <article id="article"> <div><section>This section should have a pink background.</section></div> </article> </body> </html>

jsbin示例: http ://jsbin.com/yuqeriwoxeqa/1/

I'm using html5shiv for enabling styling for HTML5 elements.

When I clone a non-HTML5 element (and only non-HTML5 elements) that have HTML5 element children, the child is not recognised by IE8.

In the following example, the first section is pink, while the cloned version is not.

<!doctype html> <html> <head> <style> div section { background:#f0f; display:block; } </style> <script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.2/html5shiv.min.js"></script> <script src="//code.jquery.com/jquery-1.11.1.min.js"></script> <script> jQuery(function ($) { $('#article').append($('div').clone()); }); </script> </head> <body> <article id="article"> <div><section>This section should have a pink background.</section></div> </article> </body> </html>

jsbin example: http://jsbin.com/yuqeriwoxeqa/1/

最满意答案

这是IE8本身不支持html5元素的结果。 尝试以下两种解决方案之一:

$('#article').append($('div').get(0).cloneNode()); 或http://pastie.org/935834

It's a result of IE8 not supporting html5 elements natively. Try one of the following two solutions:

$('#article').append($('div').get(0).cloneNode()); or http://pastie.org/935834

更多推荐

本文发布于:2023-08-04 03:33:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1405340.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:元素   无法识别   recognised   parent   cloned

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!