1024ES6

11.ES6字符串startsWith、endsWith和字符串

2019-02-12  本文已影响1人  圆梦人生

在ES6中字符串扩展了startsWith、endsWith和字符串模板
1、startsWith 开始是否包含
2、endsWith 结尾是否包含
3、字符串模板(``)

案例

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>字符串扩展</title>
    <script>
        // 1、startsWith 开始是否包含
        let str = 'www.baidu.com'
        // true
        console.log(str.startsWith('www'));
        // 2、endsWith 结尾是否包含
        console.log(str.endsWith('com'));
        // 3、字符串模板
        let tmp = `
                <ul>
                    <li>1</li>
                    <li>2</li>
                </ul>`;
        console.log(tmp);
        window.onload =  function(){
            document.getElementById('tmpid').innerHTML = tmp
        }
    </script>
</head>
<body>
    <div id='tmpid'> </div>
</body>
</html>

上一篇 下一篇

猜你喜欢

热点阅读