如何解决像 'some ${string}' 这样的 ECMAScript 模板文字不起作用
JavaScript模板文字需要反引号,而不是直引号。
您需要使用反引号(也称为“重音符号” -如果您使用 QWERTY 键盘,您会在 1 键旁边找到它) - 而不是单引号 - 来创建模板文字。
反引号在许多编程语言中很常见,但对于 JavaScript 开发人员来说可能是新的。
例子:
categoryName="name";
categoryElements="element";
console.log(`categoryName: ${this.categoryName}\ncategoryElements: ${categoryElements} `)
输出:
VM626:1 categoryName: name
categoryElements: element
解决方法
我想尝试使用模板文字,但它不起作用:它显示的是文字变量名称,而不是值。我正在使用 Chrome v50.0.2(和 jQuery)。
例子
console.log('categoryName: ${this.categoryName}\ncategoryElements: ${this.categoryElements} ');
输出
${this.categoryName}
categoryElements: ${this.categoryElements}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。