代码之家  ›  专栏  ›  技术社区  ›  Gad D Lord

如何将“放入HTML属性值中”

  •  2
  • Gad D Lord  · 技术社区  · 16 年前

    我希望有以下内容:

    <span title="This is a "good" title.">Catch me in the rice.</span>
    

    很明显,浏览器并没有很好地呈现这一点。请向我提供“我必须使用”之类的转义序列或编码的信息。

    3 回复  |  直到 11 年前
        1
  •  2
  •   Mathias Bynens    13 年前

    用相应的HTML实体替换引号,例如 &quot; &#34; )像这样:

    <span title="This is a &quot;good&quot; title.">Catch me in the rice.</span>
    <span title="This is a &#34;good&#34; title.">Catch me in the rice.</span>
    

    或者,在属性值中需要双引号的情况下,可以在HTML中使用单引号:

    <span title='This is a "good" title.'>Catch me in the rice.</span>
    
        2
  •  5
  •   Glen Solsberry    16 年前

    使用 &quot; 相反。

        3
  •  1
  •   Gordon Bell    16 年前
    <span title="This is a &quot;good&quot; title.">Catch me in the rise.</span>
    
    推荐文章