[英]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,然后在单引号上使用'
var tooltip = tooltip.replace(/'/g, "'");
Fixed this myself. 自己修复此问题。
So I just replaced every instance of ' to \\' in str_replace function :) 所以我只是在str_replace函数中替换了'to \\'的每个实例:)
WAS: 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 ’
使用
’
for Special Characters in HTML. HTML中的特殊字符。
<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>
I created Working Demo with
alert()
you can run this code snippet :)我用
alert()
创建了工作演示,您可以运行以下代码片段:)
<span onmouseover="alert('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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.