转义引号-还有其他可以使用的字符吗?
我了解 javascript 的转义引号等。是否有任何其他字符可以用来封装整个内容,而不仅仅是“或'?这两个字符都会出现在我的文本片段中,我不想在每个实例之前添加一个/
所以,而不是:
("Some text where he said "I like this, she say's")
类似这样的东西(虽然我不希望使用百分号)
(%Some text where he said "I like this, she say's%
希望这有点道理,谢谢!
I understand escaping quotes etc. for javascript. Are there any other characters that can be used to encase the whole thing rather than just " or '? Both characters will come up in my piece of text and I don't want to have to put a / before each instance
So, instead of:
("Some text where he said "I like this, she say's")
something like this(although I'm not expecting the percentage sign to be used)
(%Some text where he said "I like this, she say's%
Hope that makes a bit of sense! Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
文字字符串需要使用
"
或'
进行声明。在这样的声明中,需要对字符串值周围的引号进行转义。因此:两者都会被解释作为:
Literal strings need to be declared with either
"
or'
. And within such a declaration, the quotes that surround the string value need to be escaped. So:Both will be interpreted as:
不。只有
"
和'
是有效的字符串分隔符。您必须将它们转义为(作为作弊,您可以将字符串放入隐藏的
< div>
并读取 JS 中的 textContent。)(作为另一个作弊,
/Some text 他说“我喜欢这个,她说是/.source
。)No. Only
"
and'
are valid string delimiters. You have to escape them either as(As a cheat, you can put the string in a hidden
<div>
and read the textContent in JS.)(As another cheat,
/Some text where he said "I like this, she say's/.source
.)如果您正在使用来自服务器端模板语言的内容,您可能还需要担心多字节序列和“控制”字符的编码。
If you're working with content that comes from your server-side template language, you may also have to worry about encoding multi-byte sequences and "control" characters.