【问题标题】:How to use escape characters in an alt attribute inside an img element in HTML?如何在 HTML 的 img 元素内的 alt 属性中使用转义字符?
【发布时间】:2022-01-27 00:33:01
【问题描述】:

这是在alt 属性中为img 元素的替代文本使用转义字符的正确方法吗?

我有以下代码:

<h3>Option 1</h3>
<img src="image.jpg" 
     alt='Version of "Whistler\'s Mother" in cubist style'>

<br><br>

<h3>Option 2</h3>
<img src="image.jpg" 
     alt="Version of \"Whistler's Mother\" in cubist style">

以上两个选项中的任何一个都不能作为替代文本正常工作。我想显示的替代文本是:

Version of "Whistler's Mother" in cubist style

【问题讨论】:

标签: html image text alt html-escape-characters


【解决方案1】:

不,请改用HTML entity。例如。 &amp;apos;&amp;quot;

<h3>Option 1</h3>
<img src="image.jpg" 
     alt='Version of "Whistler&apos;s Mother" in cubist style'>

<br><br>

<h3>Option 2</h3>
<img src="image.jpg" 
     alt="Version of &quot;Whistler's Mother&quot; in cubist style">

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-06-25
    • 2011-12-28
    • 1970-01-01
    • 2021-08-05
    • 2011-09-27
    • 1970-01-01
    • 2018-03-24
    相关资源
    最近更新 更多