开发者

javascript escape string

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 &apos;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'
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜