开发者

Escape characters to be used in a javascript literal string

I would like to t开发者_Python百科ake a string that the user will enter to a text box in a form and turn it into a javascript literal. So I'd, for instance, turn the " character into \".

Is there any complete list of characters that would need to be escaped?


You only need to escape your delimiter and/or whatever enclosing quotes you choose (escape double quotes if you enclose your string in double, escape single otherwise).

If you're going to render it as HTML, you may wnat to convert them to entities (e.g. & -> &)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜