标签:UNC func doc tor selector tar let class 模板
用反引号 `,变量用${}
const oBox = document.querySelector(‘.box‘); let id = 1, name = ‘小马哥‘; let htmlStr = `<ul> <li> <p id=${id}>${name}</p> </li> </ul>`; oBox.innerHTML = htmlStr;
渲染结果
<div class="box">
<ul>
<li>
<p id="1">小马哥</p>
</li>
</ul>
</div>
字符串中调用函数
function f(){ return "have fun!"; } let string2= `Game start,${f()}`; console.log(string2); // Game start,have fun!
标签:UNC func doc tor selector tar let class 模板
原文地址:https://www.cnblogs.com/sunny666/p/12983914.html