【发布时间】:2014-03-06 11:20:57
【问题描述】:
我用 HTML5 制作了一个模板,该模板适用于 Chrome 和 Firefox,但不适用于 Internet Explorer(在 IE 8 上测试)。
我该如何解决这个问题?
【问题讨论】:
-
首先,我们需要一些代码...
标签: html internet-explorer web-component html5-template
我用 HTML5 制作了一个模板,该模板适用于 Chrome 和 Firefox,但不适用于 Internet Explorer(在 IE 8 上测试)。
我该如何解决这个问题?
【问题讨论】:
标签: html internet-explorer web-component html5-template
只需将“display:none”添加到您的模板。适用于即 11
<template id="fancyTemplate" style="display:none"></template>
【讨论】:
<template> 内容,无论它在 <head> 中。
我向你推荐 Neovov 的 polyfill: https://github.com/neovov/template-element-polyfill
注意:IE 11 中存在一个错误:它在渲染 DOM 之前将 移动到 元素下!所以parentNode属性不对,嵌套就会失败。 您可以在[F12]工具中看到它。
【讨论】:
获取html4shiv的副本,在IE小于9的地方使用:
<!--[if lt IE 9]>
<link rel="stylesheet" href="styles/ie.css" type="text/css"> <script src="scripts/ie/html5shiv.min.js"></script>
<![endif]-->
【讨论】:
您正在搜索html5shiv。
它'启用'所有 html5 元素,这些元素在旧 Internet Explorer 版本中不可用。
【讨论】:
<template> is not available in ANY version of IE,不仅在旧版本中。不太确定 html5shiv 是否能解决问题...
您可以尝试将<template>标签替换为<script>
<script id="fancyTemplate"></script>
【讨论】:
<script type="text/x-template" id="fancyTemplate"></script>
您可以使用 CSS 隐藏元素:template { display:none !important; }
如果您需要在其他浏览器中访问/克隆内容,请使用此 polyfill:https://github.com/jeffcarp/template-polyfill
但请记住,
<template>的内容仍然可以在 DOM 中找到并被执行——这正是标记的主要目标。没有任何 polyfill 可以阻止这种情况的发生,IE 再次拖慢了现代 Web 开发的速度。
【讨论】: