IE 11的模板标记填充 - 不适用于表格tr和td [英] Template tag polyfill for IE 11 - not working with table tr and td
问题描述
我使用polyfill js工作,它允许为不支持它的浏览器处理标记。
来源< tr> 和 我在 jsfiddle 上的示例 问题是,当我们试图从模板标签节点获取childNodes时,bb < td>
标签
$ b
elPlate.childNodes
和
$ c $它返回的都是< p> td>
children,就好像在< template>
中没有这样的标签。
我错过了什么NG?是否有解决此问题的方法?
P.S由于缺乏声誉,我无法为源问题添加评论。 必须位于< table>
内才能成为有效的HTML。在您的< template>
中,您指定了一个松散的< tr>
,它没有< table>
父级。 IE将此视为错误并将其从DOM中移除。因此,您的模板 documentFragment
不包含< tr>
和< td>
。
不幸的是,IE浏览器根本没有准备好HTML5模板标签。对微软来说,它可能需要一段时间才能实现,而现有的IE浏览器版本已经过时了。只有这样我们才能可靠地开始使用HTML5模板标记。
解决方法是:不要使用< template>
;使用< script type =template>
来探索模板解决方案。我相信他们应该工作得很好。一些流行的:
I work with polyfill js that allows to process tags for browsers that does not support it.
Source code of polyfill on jsfiddle
Source question
But I've noticed that in IE 11 this polyfill fails to work with templates that include <tr>
and <td>
tags
My sample on jsfiddle
The problem is that when we try to get childNodes from template tag node
elPlate.childNodes
it returns everything but <tr>
and <td>
children as if there were no such tags inside <template>
.
Am I missing something? Is there any workarounds for this issue?
P.S I was not able to add a comment to source issue due to lack of reputation. Sorry for that.
This is happening because <tr>
must be inside a <table>
in order to be valid HTML. In your <template>
, you have specified a loose <tr>
that doesn't have a <table>
parent. IE sees this as an error and removes it from the DOM. Hence, your template's documentFragment
does not contain the <tr>
and <td>
.
The unfortunate fact is: IE is simply not ready for HTML5 template tags. It'd probably take a loooong while for Microsoft to implement it, and for the existing IE browser versions become truly obsolete. Only then can we reliably start using HTML5 template tags.
The workaround is: do not use <template>
; explore template solutions using <script type="template">
instead. I believe they should work well. Some popular ones:
这篇关于IE 11的模板标记填充 - 不适用于表格tr和td的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!