I am trying to use a string that contains double quotes in the title attribute of an anchor. So far I tried these:
我正在尝试使用一个字符串,该字符串在锚的title属性中包含双引号。到目前为止,我尝试了以下方法:
<a href=".." title="Some \"text\"">Some text</a>
<!-- title looks like `Some \` --!>
and
和
<a href=".." title="Some "text"">Some text</a>
<!-- title looks like `Some ` --!>
Please note that using single quotes is not an option.
请注意,使用单引号不是一个选项。
8 个解决方案
#1
227
This variant -
这变种-
<a href=".." title="Some "text"">Some text</a>
Is correct and it works as expected - you see normal quotes in rendered page.
是正确的,并且它可以按预期工作—您可以在呈现的页面中看到正常的引号。
#2
19
EDIT: Link appears to be dead, so here's a snippet of the escape characters taken from a cached page on archive.org:
编辑:链接似乎是死的,所以这里有一个转义字符的片段,从archive.org上缓存的页面中获取:
< | less than sign <
@ | at sign @
] | right bracket ]
{ | left curly brace {
} | right curly brace }
… | ellipsis …
‡ | double dagger ‡
’ | right single quote ’
” | right double quote ”
– | short dash –
™ | trademark ™
¢ | cent sign ¢
¥ | yen sign ¥
© | copyright sign ©
¬ | logical not sign ¬
° | degree sign °
² | superscript 2 ²
¹ | superscript 1 ¹
¼ | fraction 1/4 ¼
¾ | fraction 3/4 ¾
÷ | division sign ÷
” | right double quote ”
> | greater than sign >
[ | left bracket [
` | back apostrophe `
| | vertical bar |
~ | tilde ~
† | dagger †
‘ | left single quote ‘
“ | left double quote “
• | bullet •
— | longer dash —
¡ | inverted excallamation point ¡
£ | pound sign £
¦ | broken vertical bar ¦
« | double left than sign «
® | registered trademark sign ®
± | plus or minus sign ±
³ | superscript 3 ³
» | double greather than sign »
½ | fraction 1/2 ½
¿ | inverted question mark ¿
“ | left double quote “
— | dash —
/EDIT
/编辑
Give this a shot
给这一枪
HTML转义字符列表。
It's a great reference for all of these characters.
这对所有这些角色都是很好的参考。
#3
6
Does "
instead of "
work?
& # 34;而不是“;工作吗?
#4
3
Using "
is the way to do it, I tried you second code snippet and it works on both Firefox and IE.
使用“;就是这么做的,我试过你第二段代码,它在Firefox和IE上都能运行。
#5
2
It may work with any character from the HTML Escape character list, but I had the same problem with a Java project. I used StringEscapeUtils.escapeHTML("Testing \" <br> <p>")
and the title was <a href=".." title="Test" <br> <p>">Testing</a>
.
它可能与HTML转义字符列表中的任何字符一起工作,但是我在Java项目中遇到了同样的问题。我使用了StringEscapeUtils.escapeHTML("测试\"
"),标题为 < / >。
It only worked for me when I changed the StringEscapeUtils to StringEscapeUtils.escapeJavascript("Testing \" <br> <p>")
and it worked in every browser.
它只在我将StringEscapeUtils改成stringescapeutills . escapejavascript(“Testing \”
”)时对我有效,并且在每个浏览器中都可以使用。
#6
1
There is at least one situation where using single quotes will not work and that is if you are creating the markup "on the fly" from Javascript. You use single quotes to contain the string and then any property in the markup can have double quotes for its value.
至少有一种情况是单引号不起作用,那就是如果您正在从Javascript创建标记“on the fly”。您可以使用单引号来包含字符串,然后标记中的任何属性都可以有双引号。
#7
0
Perhaps you can use JavaScript to solve your cross-browser problem. It uses a different escape mechanism, one with which you're obviously already familiar:
也许您可以使用JavaScript来解决跨浏览器的问题。它使用一种不同的逃避机制,显然你已经很熟悉了:
(reference-to-the-tag).title = "Some \"text\"";
It doesn't strictly separate the functions of HTML, JS and CSS the way folks want you to nowadays, but whom do you need to make happy? Your users or techies you don't know?
它并没有严格地将HTML、JS和CSS的功能与现在的人们想要的方式分开,但是你需要让谁开心呢?你不认识的用户或技术人员?
#8
-1
You can use this PHP code to list special characters...
您可以使用此PHP代码来列出特殊字符…
<table border="1"><?php for($i=33;$i<9000;$i++)echo "<tr><td>&#$i;<td>&#".$i.";"; ?></table>
#1
227
This variant -
这变种-
<a href=".." title="Some "text"">Some text</a>
Is correct and it works as expected - you see normal quotes in rendered page.
是正确的,并且它可以按预期工作—您可以在呈现的页面中看到正常的引号。
#2
19
EDIT: Link appears to be dead, so here's a snippet of the escape characters taken from a cached page on archive.org:
编辑:链接似乎是死的,所以这里有一个转义字符的片段,从archive.org上缓存的页面中获取:
< | less than sign <
@ | at sign @
] | right bracket ]
{ | left curly brace {
} | right curly brace }
… | ellipsis …
‡ | double dagger ‡
’ | right single quote ’
” | right double quote ”
– | short dash –
™ | trademark ™
¢ | cent sign ¢
¥ | yen sign ¥
© | copyright sign ©
¬ | logical not sign ¬
° | degree sign °
² | superscript 2 ²
¹ | superscript 1 ¹
¼ | fraction 1/4 ¼
¾ | fraction 3/4 ¾
÷ | division sign ÷
” | right double quote ”
> | greater than sign >
[ | left bracket [
` | back apostrophe `
| | vertical bar |
~ | tilde ~
† | dagger †
‘ | left single quote ‘
“ | left double quote “
• | bullet •
— | longer dash —
¡ | inverted excallamation point ¡
£ | pound sign £
¦ | broken vertical bar ¦
« | double left than sign «
® | registered trademark sign ®
± | plus or minus sign ±
³ | superscript 3 ³
» | double greather than sign »
½ | fraction 1/2 ½
¿ | inverted question mark ¿
“ | left double quote “
— | dash —
/EDIT
/编辑
Give this a shot
给这一枪
HTML转义字符列表。
It's a great reference for all of these characters.
这对所有这些角色都是很好的参考。
#3
6
Does "
instead of "
work?
& # 34;而不是“;工作吗?
#4
3
Using "
is the way to do it, I tried you second code snippet and it works on both Firefox and IE.
使用“;就是这么做的,我试过你第二段代码,它在Firefox和IE上都能运行。
#5
2
It may work with any character from the HTML Escape character list, but I had the same problem with a Java project. I used StringEscapeUtils.escapeHTML("Testing \" <br> <p>")
and the title was <a href=".." title="Test" <br> <p>">Testing</a>
.
它可能与HTML转义字符列表中的任何字符一起工作,但是我在Java项目中遇到了同样的问题。我使用了StringEscapeUtils.escapeHTML("测试\"
"),标题为 < / >。
It only worked for me when I changed the StringEscapeUtils to StringEscapeUtils.escapeJavascript("Testing \" <br> <p>")
and it worked in every browser.
它只在我将StringEscapeUtils改成stringescapeutills . escapejavascript(“Testing \”
”)时对我有效,并且在每个浏览器中都可以使用。
#6
1
There is at least one situation where using single quotes will not work and that is if you are creating the markup "on the fly" from Javascript. You use single quotes to contain the string and then any property in the markup can have double quotes for its value.
至少有一种情况是单引号不起作用,那就是如果您正在从Javascript创建标记“on the fly”。您可以使用单引号来包含字符串,然后标记中的任何属性都可以有双引号。
#7
0
Perhaps you can use JavaScript to solve your cross-browser problem. It uses a different escape mechanism, one with which you're obviously already familiar:
也许您可以使用JavaScript来解决跨浏览器的问题。它使用一种不同的逃避机制,显然你已经很熟悉了:
(reference-to-the-tag).title = "Some \"text\"";
It doesn't strictly separate the functions of HTML, JS and CSS the way folks want you to nowadays, but whom do you need to make happy? Your users or techies you don't know?
它并没有严格地将HTML、JS和CSS的功能与现在的人们想要的方式分开,但是你需要让谁开心呢?你不认识的用户或技术人员?
#8
-1
You can use this PHP code to list special characters...
您可以使用此PHP代码来列出特殊字符…
<table border="1"><?php for($i=33;$i<9000;$i++)echo "<tr><td>&#$i;<td>&#".$i.";"; ?></table>