ES6之字符串模板

2020-07-11  本文已影响0人  YAOPRINCESS

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>
上一篇 下一篇

猜你喜欢

热点阅读