我需要帮助使用 js 编写链接。
这就是我所拥有的,但我无法让它动起来。你能帮忙吗?
document.write('<a href=\"\http://www.domain.com/drowning-accidents/\"\ target=\"\_blank\"\ onClick=\"\trackOutboundLinktarget=(this, 'Outbound Links', 'domain.com'); return false;\"\><img src=\"images/infographic.png\" border=\"0\" class=\"borders\" alt=\"Check out the Infographic\" /></a><br /><br /></center>');
我认为这与 Outbound 周围的单引号有关...但不确定。
谢谢!
最佳答案
您需要转义单引号,因为整个字符串都包含在单引号中:
'...(this, \'Outbound Links\', \'domain.com\');...'
^ ^ ^ ^
从技术上讲,没有必要转义双引号。您只需要转义与整个字符串周围使用的引号类型相同的引号。
此外,您似乎正在转义一些奇怪的字符:
\"\http://www.domain.com/drowning-accidents/\"\ target=\"\_blank\"\
^^ ?? ^^ ?? ^^ ??
转义字符的正确模式是 \x
,而不是 \x\
。否则,第二个 \
将被误解为第二个转义序列的开始。
关于javascript - 需要帮助在 javascript 中使用 href 中的引号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15119562/