发表于: 2020-08-25 23:49:28

1 1148


今天完成的事情:

明白了数据的传递

学习取出数组


页面1

            // 链接发牌按钮
            window.onload = function () {
                // 绑定btn按钮节点
                var btn = document.getElementById("btn");
                btn.onclick = function () {
                    var playNumber = document.getElementById("playNumber");
                    button();
                    alert(playNumber.value);

                    // 设置
                    location.href = 'js任务3.html';
                    window.localStorage.setItem('a'arr)
                };
            };

页面2

            function getcookie() {
                //获取传递过来的localStorage
                console.log(window.localStorage.getItem('killer'))
                console.log(window.localStorage.getItem('person'))
                sessionStorage.setItem("killer","value");//以“key”为名称存储一个值“value”
            }

            localStorage.getItem("a");
            console.log(localStorage.getItem("a"))
            
            // 点击
            var button = document.querySelector('button');
            button.onclick = function () {
                button.textContent = "隐藏并传递给" + "号";
            }


练习取出数组中的元素

            window.onload = function () {
                // 点击按钮切换图片

                // 获取两个按钮
                var prev = document.getElementById("prev");
                var next = document.getElementById("next");

                // 要切换图片就是要修改img标签的src属性

                // 获取img标签
                var img = document.getElementsByTagName("img")[0];
                // alert(img);

                // 创建一个数组,用来保存图片的路径
                var imgArr = ["./images/pic1.jpg""./images/pic2.jpg""./images/pic3.jpg""./images/pic4.jpg""./images/pic5.jpg",]

                // 创建一个变量,用来保存当前正在显示的图片的索引
                var index = 0;

                // 获取id为info的元素
                var info = document.getElementById("info");
                // 设置提示文字
                info.innerHTML = "一共" + imgArr.length + " 张图片, 当前第" + (index + 1) + " 张";

                // 分别为两个按钮绑定单击响应函数
                prev.onclick = function () {
                    // 切换到下一张,索引自减
                    index--;

                    // 判断index是否小于0
                    if (index < 0) {
                        index = imgArr.length - 1;
                    }

                    // alert("上一张");
                    img.src = imgArr[index];

                    // 点击按钮以后,重新设置信息
                    info.innerHTML = "一共" + imgArr.length + " 张图片, 当前第" + (index + 1) + " 张";
                };

                next.onclick = function () {
                    index++;

                    if (index > imgArr.length - 1) {
                        index = 0;
                    }

                    // alert("下一张");
                    // 切换图片就是修改img的src属性
                    // 要修改一个元素的属性元素 .属性= 属性值
                    img.src = imgArr[index];

                    // 点击按钮以后,重新设置信息
                    info.innerHTML = "一共" + imgArr.length + " 张图片, 当前第" + (index + 1) + " 张";

                };
            };



明天的计划:

通过从传递的数组中取出杀手,平民,完成页面传递效果


返回列表 返回列表
评论

    分享到