你如何在 JavaScript/jQuery 中转义字符?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8582467/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do you escape characters in JavaScript/jQuery?
提问by Jonas
Possible Duplicates:
Escape single quotes in jQuery or JavaScript
Escape dynamic strings in JavaScript
How do you assign a string, in this case it's HTML code, to a JavaScript / jQuery variable?
您如何将字符串(在本例中为 HTML 代码)分配给 JavaScript / jQuery 变量?
And how do you escape double quotes and single quotes properly?
以及如何正确转义双引号和单引号?
var html = ""; // <-- HTML goes here
回答by Rodolfo
var html = "<head><title>Hello in \"quotes\"<\/title><\/head>"
var html = "<head><title>Hello in \"quotes\"<\/title><\/head>"