IE 11的模板标记填充 - 不适用于表格tr和td [英] Template tag polyfill for IE 11 - not working with table tr and td

查看:135
本文介绍了IE 11的模板标记填充 - 不适用于表格tr和td的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用polyfill js工作,它允许为不支持它的浏览器处理标记。

jsfiddle



来源< tr> 和< td> 标签

我在 jsfiddle 上的示例



问题是,当我们试图从模板标签节点获取childNodes时,bb
$ b

  elPlate.childNodes 
< tr>
< 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆