[英]Single quotes inside single quotes cause error
我有以下代码:
<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>
问题是单引号'
导致工具提示不显示...所以我的意思是如果文本包含'
工具提示将不显示...因为所有文本已经在单引号内...
有人可以帮我解决这个问题吗?
尝试将工具提示文本设置为var,然后在单引号上使用'
var tooltip = tooltip.replace(/'/g, "'");
自己修复此问题。
所以我只是在str_replace函数中替换了'to \\'的每个实例:)
WAS:
$desc = str_replace('"', "", preg_replace('/(\s\s+|\t|\n)/', ' ', JFilterOutput::cleanText($regs[0])));
就是现在:
$desc = str_replace("'", "\\'", preg_replace('/(\s\s+|\t|\n)/', ' ', JFilterOutput::cleanText($regs[0])));
使用’
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>
我用
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.