浏览器是否广泛支持属性中的数字引号? [英] Do browsers widely support numeric quotes in attributes?

查看:86
本文介绍了浏览器是否广泛支持属性中的数字引号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 < script src = myscript.jstype =text / javascript>< / script> 

...利用其他报价类型:

 < script src =&#34; myscript.js&#34;类型=安培;#34;文本/ JavaScript的&安培;#34;>< /脚本> 

在现代浏览器和使用的较旧浏览器(如IE6)中这些功能是否得到广泛支持?基本上使用这种方法是安全的,就像使用普通的双引号方法一样?






编辑: HTML4规范似乎允许它,但在实际情况中它是否得到很好的支持?

  3.2.2属性

作者也可以使用numeric代表
双引号(&#34;)和单引号(&#39;)的字符引用。

对于双引号,作者也可以使用
字符实体引用& quot ;.


解决方案

使用&#34;而不是仅仅是错误的,它在SGML和XML规范中没有相同的含义。元素的参数值应该使用单引号(')或双引号()。在旧的SGML规范中,这个元素

 < foo bar =&#34; quux&#34; /> 

可以被读取为名称为 foo 的元素,而属性named bar 值为quux。但是,该标准定义未加引号的属性值不应包含转义字符。这个元素

 < foo bar =quux/> 

应该被看作名称为 foo 的元素,而属性named bar 与不带引号的值 quux 相关联。这是因为在SGML中,引号是可选的,到下一个空格的所有内容都将用作属性的值。



XML需要引号。


There exist other ways of linking to JS, apart from this (the usual)..

<script src="myscript.js" type="text/javascript"></script>

...that utilize other quote types:

<script src=&#34;myscript.js&#34; type=&#34;text/javascript&#34;></script>

Are these widely supported in modern browsers, and older browsers in use, such as IE6? Basically is it safe to use this method, just as you would use the regular double-quote method?


Edit: The HTML4 spec seems to allow it, but is it well supported in practical reality?

3.2.2 Attributes

  Authors may also use numeric character references to represent
  double quotes (&#34;) and single quotes (&#39;).

  For double quotes authors can also use the
  character entity reference &quot;.

解决方案

Using &#34; instead of " is simply wrong, it doesn't have the same meaning within the SGML and XML specifications. Argument values of elements should use either single (') or double quotes ("). In the old SGML specification this element

<foo bar=&#34;quux&#34; />

could be read as an element with the name foo, and attribute named bar with the value "quux". However, the standard defines that unquoted attribute values should not include escaped characters. And this element

<foo bar="quux" />

should be read as an element with the name foo, and attribute named bar with the value quux without the quotes. This is because in SGML the quotes are optional, and everything up to the next space will be used as the value for the attribute.

XML requires quotes.

这篇关于浏览器是否广泛支持属性中的数字引号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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