发表于: 2020-09-16 23:45:40

0 1169


今天完成的事情:

完成任务4第二个页面的逻辑


            // 获取btn1按钮
            var btn1 = document.getElementById("btn1");
            // 获取btn按钮
            var btn2 = document.getElementById("btn2");

            // 获取传递玩家身份的数组allnum
            var allnum = localStorage.getItem("allnum");
            // 将字符串转换为数组,获取杀手,平民
            var arr = allnum.split(",")

            // 查看身份数组
            console.log(allnum)
            // 查看身份数组的元素
            console.log(arr[0])
            // 查看数组的长度
            console.log(arr.length);

            var boxs = document.getElementById("boxs");

            index = 0;

            window.onload = function () {
                box1.onclick = function () {
                    if (index < arr.length) {
                        index++;

                        var div = document.createElement("div");
                        div.className = "process";

                        var add = document.createAttribute("id");
                        add.value = "add"
                        div.setAttributeNode(add)

                        var gzText = document.createTextNode(index + "号被杀死,真实身份是" + arr[index - 1]);
                        div.appendChild(gzText);

                        // 获取id为box2的节点
                        var box2 = document.getElementById("box2");
                        // 获取id为boxs的节点
                        var boxs = document.getElementById("boxs");
                        /*  insertBefore()
                            可以在指定的子节点前插入新的子节点
                            语法:父节点.insertBefore(新节点,旧节点);
                        */
                        boxs.insertBefore(divbox2);
                    }
                };

                box1.onclick = function () {
                    location.href = 'js任务4-1.html';
                    window.localStorage.setItem('allnum'arr)
                };


                btn2.onclick = function () {
                    location.href = 'js任务4-1.html';
                    window.localStorage.setItem('allnum'arr)

                };
            };



明天的计划:

学习页面的跳转关联


返回列表 返回列表
评论

    分享到