【问题标题】:ES6 String Substitution does not workES6 字符串替换不起作用
【发布时间】:2019-01-08 14:37:37
【问题描述】:

test.html:

<!DOCTYPE html>
<html>
<head>
    <title>Test</title>
</head>
<body>
    <script src="test.js"></script>
</body>
</html>

test.js:

let fName = "Nick";
let lName = "Lee";

document.write('${fName}');

Chrome 上的输出:

${fName}

我以为是尼克。

【问题讨论】:

标签: javascript html ecmascript-6


【解决方案1】:

'${fName}' 被视为常规字符串。你应该使用字符串模板:

document.write(`${fName}`);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-15
    • 2016-10-05
    • 2012-07-08
    • 2011-08-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多