ES6 模板字符串: ~ 变量 ~
<div id="app"></div> <script> /* 找到对应id */ let item = document.getElementById('app'); /* 声明变量 */ let username1 = 'ann'; let username2 = 'ben'; /* 替换内容 */ item.innerHTML = ` <h1> hello ${username1}</h1> <h2> hello ${username2}</h2> ` </script>