我有一个 php 页面,当用户将产品添加到购物车时,我会在该页面上显示 jQuery 警报。警报中显示的消息是来自存储所有语言元素的 php 页面的变量。
$cartaddeditem='The product was added to your cart.\r\n You can view your <a href=\'cart.php?action=show\'>shopping cart</a> or click OK to continue shopping';
然后,在页面上:
<body onload="jAlert('success', '<?=$cartaddeditem?>', '<?=$minicart?>');" <? } >
问题是由于 $cartaddeditem var 中的引号导致警报无法触发,并且我在 firebug 中收到错误消息:
Error: missing ) after argument list
Line: 1, Column: 22
Source Code:
jAlert('success', The product was added to your cart.\r\n You can view your <a href=\
如何转义 jQuery 消息字符串中的引号?我尝试了几种带有双引号和单引号、一两个反斜杠的转义类型,但没有任何效果。