美文网首页1024ES6
11.ES6字符串startsWith、endsWith和字符串

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

作者: 圆梦人生 | 来源:发表于2019-02-12 22:27 被阅读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>

相关文章

网友评论

    本文标题:11.ES6字符串startsWith、endsWith和字符串

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