Jak uniknąć podwójnych cudzysłowów w atrybucie tytułu

Próbuję użyć łańcucha, który zawiera podwójne cudzysłowy w atrybucie TITLE kotwicy. Do tej pory próbowałem tych:

<a href=".." title="Some \"text\"">Some text</a>
<!-- title looks like `Some \` --!>

I

<a href=".." title="Some &quot;text&quot;">Some text</a>
<!-- title looks like `Some ` --!>

Należy pamiętać, że używanie pojedynczych cudzysłowów jest , a nie opcją.

Author: Mark Schultheiss, 2010-09-20

8 answers

Ten wariant -

<a href=".." title="Some &quot;text&quot;">Some text</a>

Jest poprawne i działa zgodnie z oczekiwaniami - w renderowanej stronie widzisz normalne cudzysłowy.

 235
Author: Māris Kiseļovs,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2010-09-20 15:13:17

EDIT: Link wydaje się martwy, więc oto fragment znaków ucieczki zaczerpnięty z buforowanej strony na archive.org :

&#060   |   less than sign  <       
&#064   |   at sign @       
&#093   |   right bracket   ]       
&#123   |   left curly brace    {       
&#125   |   right curly brace   }       
&#133   |   ellipsis    …       
&#135   |   double dagger   ‡       
&#146   |   right single quote  ’       
&#148   |   right double quote  ”       
&#150   |   short dash  –       
&#153   |   trademark   ™       
&#162   |   cent sign   ¢       
&#165   |   yen sign    ¥       
&#169   |   copyright sign  ©       
&#172   |   logical not sign    ¬       
&#176   |   degree sign °       
&#178   |   superscript 2   ²       
&#185   |   superscript 1   ¹       
&#188   |   fraction 1/4    ¼       
&#190   |   fraction 3/4    ¾       
&#247   |   division sign   ÷       
&#8221  |   right double quote  ”       
&#062   |   greater than sign   >   
&#091   |   left bracket    [   
&#096   |   back apostrophe `   
&#124   |   vertical bar    |   
&#126   |   tilde   ~   
&#134   |   dagger  †   
&#145   |   left single quote   ‘       
&#147   |   left double quote   “   
&#149   |   bullet  •   
&#151   |   longer dash —   
&#161   |   inverted excallamation point    ¡   
&#163   |   pound sign  £   
&#166   |   broken vertical bar ¦   
&#171   |   double left than sign   «   
&#174   |   registered trademark sign   ®   
&#177   |   plus or minus sign  ±   
&#179   |   superscript 3   ³   
&#187   |   double greather than sign   »   
&#189   |   fraction 1/2    ½   
&#191   |   inverted question mark  ¿   
&#8220  |   left double quote   “   
&#8212  |   dash    —   

/EDIT

Give this a shot

HTML Escape character list.

To świetne odniesienie do wszystkich tych postaci.
 20
Author: Dave,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-02-21 13:42:16

Kod ucieczki &#34; może być również użyty zamiast &quot;.

 7
Author: fredley,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-07-30 16:40:24

Używanie &quot; jest sposobem, aby to zrobić, próbowałem Ci drugi fragment kodu i działa zarówno na Firefoksie, jak i IE.

 3
Author: TheCee,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2010-09-20 15:25:27

Może działać z dowolnym znakiem z HTML Escape character list , ale miałem ten sam problem z projektem Java. Użyłem StringEscapeUtils.escapeHTML("Testing \" <br> <p>") i tytuł brzmiał <a href=".." title="Test&quot; &lt;br&gt; &lt;p&gt;">Testing</a>.

Zadziałało tylko u mnie, gdy zmieniłem StringEscapeUtils na StringEscapeUtils.escapeJavascript("Testing \" <br> <p>") i działało w każdej przeglądarce.

 2
Author: Rodrigo Horta,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-03-14 13:52:14

Jest co najmniej jedna sytuacja, w której używanie pojedynczych cudzysłowów nie będzie działać i to jest, jeśli tworzysz znaczniki "w locie" z Javascript. Pojedyncze cudzysłowy zawierają ciąg znaków, a następnie każda właściwość w znacznikach może mieć podwójne cudzysłowy dla swojej wartości.

 1
Author: cvadillo,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-09-17 17:26:33

Być może możesz użyć JavaScript, aby rozwiązać problem między przeglądarkami. Używa innego mechanizmu ucieczki, z którym oczywiście jesteś już zaznajomiony:

(reference-to-the-tag).title = "Some \"text\"";

To nie ściśle oddziela funkcje HTML, JS i CSS sposób ludzie chcą cię w dzisiejszych czasach, ale kogo trzeba uszczęśliwić? Twoi użytkownicy lub techies, których nie znasz?

 0
Author: WebManWalking,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-01-25 09:43:06

Możesz użyć tego kodu PHP do wyświetlenia znaków specjalnych...

<table border="1"><?php for($i=33;$i<9000;$i++)echo "<tr><td>&#38;#$i;<td>&#".$i.";"; ?></table>
 -2
Author: user6000975,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-01-25 09:53:31