[英]Escape dollar sign in JavaScript template literals (template strings)
我正在使用 JavaScript ES6 Docs Here的新模板文字(模板字符串)语法,我不太确定如何转义用于破坏字符串以添加参数的美元符号。
这是我正在尝试做的事情:
var response = `I consent to my credit card being charged in the amount of
$ ${ total } for the purchase of ${ item.title } and any
applicable sales tax.`
效果很好......但我真的不想有那个空间$ ${title}
这使得最终结果看起来像:
...购买金额为 25.99 美元...
我真的更喜欢
...购买金额为 25.99 美元...
我想这没问题,或者显然我可以使用仍然有效的旧方法,但很高兴知道如何解决这个问题。 我链接到 Mozilla 文档,但我在其中找不到任何关于它的内容,希望有人知道如何解决这个问题
$
不产生文字$
的唯一情况是在{
之前,否则您不需要对其进行转义。
var response = `You have $${money}`
因此确实有效。 如果您需要转义任何内容,反斜杠\\
也是模板字符串中的转义字符,因此(虽然不必要)以下内容也适用:
var response = `You have \$${money}`
var response = `I consent to my credit card being charged in the amount of
$${ total } for the purchase of ${ item.title } and any
applicable sales tax.`
在美元符号前面加一个反斜杠是我想到的第一件事,它有效:
\${DEPLOYMENT_NAME}
这对我有用。
var response = `You have \$\{money}`;
<v-btn :href="mail">
Send Mail
</v-btn>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.