I have the following string:
'You've just created'
When I assign this string to a JavaScript variable, this is interpreted as 2 strings because there's a '
charact开发者_开发问答er.
How can I escape it?
In JS code blocks, use a backslash:
var text = 'You \'ve just created'
in JS inside HTML, use a HTML entity:
<a onclick='alert("You 've just created");'>
You can use either " or ' to quote a string, so you could do it this way:
"You've just created"
or you can use a \ to quote just one character:
'You\'ve just created'
精彩评论