如何使用Javascript中的单引号和双引号来容纳字符串 [英] How can I accommodate a string with both single and double quotes inside of it in Javascript
本文介绍了如何使用Javascript中的单引号和双引号来容纳字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
谢谢,我猜是不是有可能,有人知道一个简单而简单的方法来逃避这些引号,所以我可以把它放在一个字符串中?请记住,这个字符串的一部分将是我以后需要执行的javascript。
谢谢!
解决方案
您需要转义引号 \
:
var someString ='escape all the quotation marks \\ \\\;
I have an application, and it is fed some HTML. It then needs to put that HTML into a string. This HTML contains single and double quotes. Is it possible, in javascript, to declare a string with information inside of it, that does not use single or double quotes?
Thanks, and I guess if it is not possible, does anyone know a simple and easy way to escape these quotes so I can put it in a string? Keep in mind, part of this string will be javascript that I will later need to execute.
Thanks!
解决方案
You need to escape the quotation characters with \
:
var someString = 'escape all the quotation marks \"\'';
这篇关于如何使用Javascript中的单引号和双引号来容纳字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文