发表于: 2020-07-25 21:19:06
1 1307
今天完成的事情:
学习了js的知识
任务4的进度
//点击弹出提示框
var quit = document.getElementById("quit");//取出返回键值
quit.onclick = function (){
var box = confirm("确认退出游戏吗?");
if(box == true){//判断是否退出游戏
location.href="2.html";
}
}
//取出初始值
var first = localStorage.getItem('firstDay');
//父元素值
var main = document.querySelector("main");
//生成div
for (var i = 0; i < first;i++){
var nav = document.createElement("nav");
main.appendChild(nav);
var title = document.createElement('div');
title.id = 'title';
title.innerHTML = '第1天'
nav.appendChild(title);
var uls = document.createElement('ul')
nav.appendChild(uls);
var png = document.createElement('div');
png.className = 'png';
uls.appendChild(png);
var img1 = document.createElement('img');
img1.className = 'img1';
img1.src ="13w/月亮.png";
png.appendChild(img1);
var img2 = document.createElement('img');
img2.className = 'img2';
img2.src ="13w/太阳.png";
png.appendChild(img2);
var lis = document.createElement("li");
lis.innerHTML = '杀手杀人';
lis.id = 'li0';
uls.appendChild(lis);
var span = document.createElement('span');
span.innerHTML = '1号被杀手杀死,真实身份是平民';
uls.appendChild(span);
var span1 = document.createElement('span');
span1.innerHTML = '11111111';
uls.appendChild(span1);
var lis1 = document.createElement('li');
lis1.innerHTML = '亡灵发表遗言';
lis1.id = 'li1';
uls.appendChild(lis1);
var lis2 = document.createElement('li');
lis2.innerHTML = '讨论';
lis2.id = 'li2'
uls.appendChild(lis2);
var lis3 = document.createElement('li');
lis3.innerHTML = '投票';
lis3.id = 'li3';
uls.appendChild(lis3);
}
//获取下拉框属性
var title = document.querySelectorAll('#title');
var ul = document.querySelectorAll("ul");
//添加事件
for(var i = 0;i<title.length;i++){
ul[i].style.display = 'block';
title[i].index = i;
title[i].onclick = function(){
if(ul[this.index].style.display == "block"){
ul[this.index].style.display = "none";
}else if(ul[this.index].style.display == 'none'){
ul[this.index].style.display = 'block';
}
}
}
//获取点击内容
var li0s = document.querySelectorAll('#li0');
var li1s = document.querySelectorAll('#li1');
var li2s = document.querySelectorAll('#li2');
var li3s = document.querySelectorAll('#li3');
//添加事件
for(i = 0;i<title.length;i++){
li0s[i].index = i;
li0s[i].onclick = function(){
if(this.style.background == ''){//背景颜色未变则触发事件
alert('请杀手杀人');
this.style.background = "#6f949d";
//location.href = "2-5.html";
}
}
li1s[i].onclick = function(){
if(this.style.background == ''){
}
}
}
明天计划的事情:
继续完成任务
评论