我正在使用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
更多推荐
发布评论