引用HTML属性值 [英] quoting HTML attribute values

查看:105
本文介绍了引用HTML属性值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道规范允许和作为属性值的分隔符,并且我也知道这是一个很好的习惯来总是引用 a>。



然而,我认为是更简洁的方式,也许这只是我用C和C ++的语法成长起来的。



引用属性值的最简洁方式是什么?为什么?请不要主观回答。

您可以降低导致错误的动态值的风险。例如

 < input value ='$ {lastName}'/> 

<输入值='O'Graddy'/>
^^^^^^^

vs。

 < input value =$ {lastName}/> 

< input value =O'Graddy/>


I know the spec allows both ' and " as delimiters for attribute values, and I also know it's a good practice to always quote.

However I consider " being the cleaner way, maybe it's just me having grown up with C and C++' syntax.

What is the cleanest way of quoting attribute values and why? Please no subjective answers.

解决方案

Both are fine, but Double quotes are better (IMHO) as you reduce the risk of dynamic values causing errors. e.g.

<input value='${lastName}'/>

<input value='O'Graddy'/>
                ^^^^^^^

vs.

<input value="${lastName}"/>

<input value="O'Graddy"/>

这篇关于引用HTML属性值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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