简体   繁体   中英

Single quotes inside single quotes cause error

I have this code:

<span onmouseout="tooltip.hide();" onmouseover="tooltip.show('Hello. This is a simple tooltip, I'm here if you need me, we've been away for some time.');" class="hotspot">test link</span>

the thing is that the SINGLE quote ' is causing the tooltip not to show... so I mean IF the text contains ' the tooltip will not show... because all the text is already inside single quotes...

Can someone please help me to fix this?

尝试将工具提示文本设置为var,然后在单引号上使用&apos;

var tooltip = tooltip.replace(/'/g, "&apos;");

Fixed this myself.

So I just replaced every instance of ' to \\' in str_replace function :)

WAS:

$desc = str_replace('"', "",  preg_replace('/(\s\s+|\t|\n)/', ' ', JFilterOutput::cleanText($regs[0]))); 

IS NOW:

$desc = str_replace("'", "\\'",  preg_replace('/(\s\s+|\t|\n)/', ' ', JFilterOutput::cleanText($regs[0]))); 

Use &rsquo; for Special Characters in HTML.

<span onmouseout="tooltip.hide();" onmouseover="tooltip.show('Hello. This is a simple tooltip, I&rsquo;m here if you need me, we&rsquo;ve been away for some time.');" class="hotspot">test link</span>

I created Working Demo with alert() you can run this code snippet :)

 <span onmouseover="alert('Hello. This is a simple tooltip, I&rsquo;m here if you need me, we&rsquo;ve been away for some time.');" class="hotspot">test link</span> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM