我可以在HTML属性值中添加什么值? [英] What values can I put in an HTML attribute value?

查看:81
本文介绍了我可以在HTML属性值中添加什么值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在html属性值中转义引号吗?什么字符被允许?



这是否有效?

 < span title =这是一个'好'的标题。>嗨< / span> 


解决方案

如果您的属性值被引用(开始和结束于双引号),那么除了双引号和&符号之外的任何字符都是允许的,它必须被引用为& quot; &#34; 和<$ c>)和& amp; &#38;



你也可以在属性值周围使用单引号,如果你这样做,在属性中使用文字双引号:< span title ='这是一个好的标题。'> ...< / span> 。在这样一个属性值中转义单引号,你必须使用数字实体引用&#39; ,因为一些浏览器不支持命名实体& (这是未在HTML 4.01中定义)。



此外,您还可以创建属性wi没有引号,但是这限制了你可以在其中更多的字符集,不允许使用空格, = '< > `



请参阅 HTML5规范了解更多详情。


Do I need to escape quotes inside of an html attribute value? What characters are allowed?

Is this valid?

<span title="This is a 'good' title.">Hi</span>

解决方案

If your attribute value is quoted (starts and ends with double quotes "), then any characters except for double quotes and ampersands are allowed, which must be quoted as &quot; and &amp; respectively (or the equivalent numeric entity references, &#34; and &#38;)

You can also use single quotes around an attribute value. If you do this, you may use literal double quotes within the attribute: <span title='This is a "good" title.'>...</span>. In order to escape single quotes within such an attribute value, you must use the numeric entity reference &#39; since some browsers don't support the named entity, &apos; (which was not defined in HTML 4.01).

Furthermore, you can also create attributes with no quotes, but that restricts the set of characters you can have within it much further, disallowing the use of spaces, =, ', ", <, >, ` in the attribute.

See the HTML5 spec for more details.

这篇关于我可以在HTML属性值中添加什么值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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