我正在尝试将转义字符串呈现为 html 属性(使用 Twitter Bootstrap 呈现用于生成用户正在查看的内容的转义代码的弹出框):
就像是:
<a class="btn" href="#" data-content='<pre>$escaped_code</pre>' rel="popover" data-orginal-title="$title">some cool looking thing</a>
问题是浏览器会解析和取消转义转义码,这可能会导致不愉快。
我正在尝试将转义字符串呈现为 html 属性(使用 Twitter Bootstrap 呈现用于生成用户正在查看的内容的转义代码的弹出框):
就像是:
<a class="btn" href="#" data-content='<pre>$escaped_code</pre>' rel="popover" data-orginal-title="$title">some cool looking thing</a>
问题是浏览器会解析和取消转义转义码,这可能会导致不愉快。
不要在 HTML 属性中使用<
or ,例如:>
<a class="btn" href="#" data-content='<pre>$escaped_code</pre>' rel="popover" data-orginal-title="$title">some cool looking thing</a>
我不确定你那里有什么样的转义字符串。我假设PHP。但是,转义字符对于 HTML 是不同的:
http://www.theukwebdesigncompany.com/articles/entity-escape-characters.php
您尝试将 HTML 标记放入 HTML 属性的事实表明您没有使用正确的 HTML 转义字符。确保 HTML 标记中的所有内容都针对 HTML 进行了转义。
答案当然是手动转义两次。