在JavaScript中将纯文本转换为字符串文字
使用JavaScript,有没有办法将纯文本(带有特殊字符)转换为JavaScript字符串文字在JavaScript中将纯文本转换为字符串文字,javascript,Javascript,使用JavaScript,有没有办法将纯文本(带有特殊字符)转换为JavaScript字符串文字 "Here is some text inside quotes."Here is more text inside quotes: it's not easy to write this as a string literal, so I need to automatically convert it somehow." " 例如,有没有办法将以下文本转换为字符串文字 "Here is so
"Here is some text inside quotes."Here is more text inside quotes: it's not easy to write this as a string literal, so I need to automatically convert it somehow." "
例如,有没有办法将以下文本转换为字符串文字
"Here is some text inside quotes."Here is more text inside quotes: it's not easy to write this as a string literal, so I need to automatically convert it somehow." "
课文是从哪里来的?在创建双引号/嵌套引号字符串时,处理它们可能更容易。我真的不明白这个问题。。。文本来自哪里?当然它已经是字符串文字了?@DavidThomas在这种情况下,我需要为字符串中的每个引号(以及其他所有特殊字符)键入转义字符。有时有必要将HTML作为字符串嵌入JavaScript中,这是我想到的主要用例。不一定,但不知道它来自何处,很难提出任何替代方案。更多的信息往往导致更好的答案。你可能是对的,这可能正是你必须要做的,但总有机会找到更好的方法。请参见“”上的。似乎没有人理解这里的问题。他。。而且我。。正在寻找发电机。。比如谷歌翻译。。如果你在生成器中放入一个文本,它会给你一个有效的JS字符串。