旧版浏览器中的 HTML5 样式脚本标签
有人指出,在 HTML 5 中,可以使用 Javascript 的 script
标签不带任何属性,如下所示:
<script>
// the javascript here
</script>
借助 HTML 5 中的其他功能,您可以使用不同类型的poly-fills 弥补了旧浏览器不了解 HTML 5 的问题,但是上面的 script
标签在任何旧浏览器中是否会产生副作用?
更新:让我们将限制设置为 IE6 及更高版本以及 Firefox 2 及更高版本,以获得具体的内容。 >
It has been stated that in HTML 5 it's OK to use script
-tags for Javascript without any attributes, like this:
<script>
// the javascript here
</script>
With other features in HTML 5 you can use different kind of poly-fills to bridge what old browsers don't know about HTML 5, but can above script
-tag have any side-effect in any old browser?
UPDATE: Let's set the limit at IE6 and above, along with Firefox 2 and above, to have something concrete.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这在任何地方都很好 - type 的默认值是您无论如何要键入的值,如浏览器所解释的那样。我在我制作的每个网站上都使用过它并且从未遇到过问题。脚本也是如此 - 没有必要指定默认值。
HTML4 规范(http://www.w3.org/TR/html4/interact/scripts.html#h-18.2.1)表示该类型是必需的,尽管浏览器已经习惯了这种格式错误(指定的语言没有type,
application/javascript
而不是type/javascript
等。简而言之,浏览器已经习惯了这种错误,因此它们会寻找脚本,甚至不解析据我所知。This is fine everywhere - the default value for type is the one you'd type anyway, as interpreted by browsers. I've used this on every site I've ever made and have never had problems. The same goes for script - no point specifying default values.
The HTML4 spec (http://www.w3.org/TR/html4/interact/scripts.html#h-18.2.1) says the type is required, though browsers are used to this being malformed (language being specified with no type,
application/javascript
instead oftype/javascript
etc. In short, browsers are used to this being wrong, so they look for script, and don't even parse the attributes as far as I can tell.