美文网首页
ES6之字符串模板

ES6之字符串模板

作者: YAOPRINCESS | 来源:发表于2020-07-11 15:07 被阅读0次

    image.png

    <!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>Document</title>
    </head>
    <body>
        <script>
            
            //ES6新增的API
            let str="helloworld";
            console.log(str.startsWith("hello"));//true
            console.log(str.endsWith("rld"));//true
            console.log(str.includes("wo"));//true
            console.log(str.includes("hello"));//true
    
            //字符串模板
            let ss=`
    <div>
        <span>hello world</span>
    </div>
            `;
            console.log(ss);
    
            //使用变量
            function fun(){
                return "这是一个函数"
            }
            let name="kkk";
            let age=11;
            let string=`
            name:${name}
            age:${age}
            表达式name:${name+10}
            表达式age:${age+10}
            调用方法名:${fun}
            调用方法:${fun()}
            `
            console.log(string);
        </script>
    </body>
    </html>
    

    相关文章

      网友评论

          本文标题:ES6之字符串模板

          本文链接:https://www.haomeiwen.com/subject/ruricktx.html