发表于: 2020-09-18 23:58:29

1 1019


今天完成的事情:

完成点击变色的事件


            var index = 0
            window.onload = function () {
                //添加div
                for (index = 0index < arr.lengthindex++) {
                    // 创建名为playerbox的div
                    var box = document.createElement("div");
                    box.className = "playerbox";
                    box.setAttribute("data-idx"index)

                    // 设置box中的内容
                    box.innerHTML =
                        "<p class='name'>" + (arr[index]) + "</p>" +
                        "<p class='number'>" + (index + 1) + "号" + "</p>" +
                        "<div class='playerpic'>" +
                        "<img class='img' src='./images/src/发言讨论结束,投票_04.png'>" +
                        "</div>";

                    var boxs = document.getElementById("boxs");//获取boxs的节点
                    boxs.appendChild(box);// 将boxs添加到box中

                    // console.log(index);
                    // console.log(arr[index]);

                    var array = index
                    console.log(array);

                    // 方法1
                    box.onclick = function () {
                        console.log(this.getAttribute('data-idx'))
                        console.log(this);
                        this.style.backgroundColor = "#83b09a";
                        event.srcElement.style.backgroundColor = "#83b09a";
                        console.log(event);
                    };

                    // // 方法2
                    // box.onclick = function (event) {
                    //     event.srcElement
                    //     event.srcElement.style.backgroundColor = "#83b09a";
                    // }

                    btn.onclick = function () {
                        location.href = 'js任务4-2.html';
                        window.localStorage.setItem('allnum'arr)
                        document.getElementByIdx("btn").disabled = true;
                    };





返回列表 返回列表
评论

    分享到