xinggevip

es2015字符串拼接
Demo1<script> window.onload = function (){ ...
扫描右侧二维码阅读全文
09
2019/06

es2015字符串拼接

Demo1

<script>
    window.onload = function (){
        // 字符串模板--拼接操作
        let name = 'Tom';
        let age = 22;
        let str = `大家好我叫${name},今年${age}岁了`;
        console.log(str);
    }
</script>

运行结果

大家好我叫Tom,今年22岁了

Demo2

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

</head>
<body>

<ul id="demo"></ul>



<script>

    let arr = [
        {
            title:"习近平:阿芙乐尔号巡洋舰对中国人民意义非凡",
            read:100
        },
        {
            title:"记习近平在俄罗斯的54小时",
            read:100
        },
        {
            title:"搬梯子,还是扔砖头  筑起技术经济安全“防火墙”",
            read:100
        },
        {
            title:"浙江念好乡村治理“三治经” 走乡村善治之路",
            read:100
        },
    ];
    window.onload = function () {
        // 测试遍历数组
        for (let i = 0; i < 4; i++){
            console.log(arr[i].title,arr[i].read);
        };
        let oul = document.querySelector('#demo');
        for (let i = 0; i < arr.length;i++){
            var oli = document.createElement('li');
            // oli.innerHTML = '<span>' + arr[i].title +'</span>'+ '<span>' + arr[i].read +'</span>';
            oli.innerText = `${arr[i].title}--阅读量为${arr[i].read}`;
            oul.appendChild(oli);
        }

    }
</script>
</body>
</html>

运行结果

●习近平:阿芙乐尔号巡洋舰对中国人民意义非凡--阅读量为100
●记习近平在俄罗斯的54小时--阅读量为100
●搬梯子,还是扔砖头 筑起技术经济安全“防火墙”--阅读量为100
●浙江念好乡村治理“三治经” 走乡村善治之路--阅读量为100
Last modification:June 10th, 2019 at 09:23 pm
If you think my article is useful to you, please feel free to appreciate

Leave a Comment