<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>es6模板字符串</title>
</head>
<body>
<div id="template"></div>
<div id="newTemplate"></div>
<script>
/*
* 模板字符串、添加变量、添加函数
*/
let name = "henrey";
function makeUppercase (word) {
return word.toUpperCase();
}
// es5
let template = '<h1>Hello World!</h1>' +
'<p>这里是模板字符串相关使用方法介绍!</p>' +
'<ul>' +
'<li>1</li>' +
'<li>2</li>' +
'<li>3</li>' +
'</ul>'
//es6
let newTemplate = ` <h1>${makeUppercase('Hello')},${name}</h1>
<p>这里是模板字符串相关使用方法介绍</p>
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
</ul> `
document.getElementById("template").innerHTML = template;
document.getElementById("newTemplate").innerHTML = newTemplate;
</script>
</body>
</html>
es6 模板字符串
最新推荐文章于 2022-07-07 09:04:18 发布