以 IMG 为例,正确的写法是(为了明显,我们指定了width和height属性):
<img src="..." alt="
中国 西安" width="100" height="50" />
假如alt属性不要引号,效果如下:
<img src="..." alt=
中国 西安 width="100" height="50" />
可以看出alt属性值在空格处中断了。
假如alt属性使用单引号,属性中也含有单引号时,效果如下:
<img src="..." alt='
xi'an' width="100" height="50" />
可以看出alt属性值在单引号处中断了。
所以应该使用双引号把属性值括起来,当在属性值中遇到双引号时,用
"代替
<img src="..." alt="
"" width="100" height="50" />
正确!