[英]Single quote escape in JavaScript Alert() function
I am showing some French line through javascript alert function
and the French line looks like: 我通过
javascript alert function
显示一些法语行,法语行看起来像:
S'il vous plaît accepter les termes et conditions avant de procéder
And alert look like in page source: 警报看起来像页面源:
alert('S'il vous plaît entrer une adresse email valide!');
Firebug is showing an error message like: Firebug显示如下错误消息:
SyntaxError: missing ) after argument list
参数列表后面的SyntaxError:missing)
I try to escape the French line like: 我试图逃脱法国线:
alert('S\\'il vous plaît entrer une adresse email valide!');
alert('S\\\'il vous plaît entrer une adresse email valide!');
alert('S"'"il vous plaît entrer une adresse email valide!');
All guidelines were followed, but nothing works. 遵循所有准则,但没有任何作用。 So how do I fix it?
那么我该如何解决呢?
Try - 试试 -
alert("S'il vous plaît entrer une adresse email valide!");
This is probably the simplest approach. 这可能是最简单的方法。 Whenever you need to pass a single quote in a string, wrap it inside a double quote, and vice versa.
每当您需要在字符串中传递单引号时,将其包含在双引号内,反之亦然。
If you have a mix of single and double quote in a string, then wrap it inside either single quotes or double quotes, and escape the corresponding ones in the string using a single backslash - 如果在字符串中混合使用单引号和双引号,则将其包装在单引号或双引号内,并使用单个反斜杠转义字符串中的相应引号 -
alert("So she said, \"Hey!, how are you?\". I said, 'I am fine, thanks'.")
一个反斜杠。
alert('S\\'il vous plaît entrer une adresse email valide!')
正确使用转义序列
alert('S\'il vous plaît entrer une adresse email valide!')
You're not escaping correctly. 你没有正确逃脱。
Try this: 尝试这个:
alert('S\'il vous plaît entrer une adresse email valide!');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.