- 这篇博客只是本身的学习笔记,供往后复习所用,没有通过精心排版,也没有按逻辑编写
- GitHub项目源码
- 预览地址
哈希,数组
作出来导航页面css
实际上数组就是hash
数组带方括号实际上是hash的一种简写.
且数组是对象.html
JS错误:没有被处理的 语法错误 :不期待的字符串]
意思就是这里不该该有字符串]
语法错误git
text-transform: uppercase; /*文本小写变大写*/
#mainxxxx{ display: inline-block; } main{ text-align: center; } /*mainxxx这个div居中*/
#mainxxxx>div:nth-child(2){ margin-left: 1em; }
#mainxxxx>div:nth-child(2)
表明mainxxxx
的名为div
的第二个子元素.程序员
定位kbd
里面的button
,并添加hover
github
kbd>button{ position: absolute; right: 0; bottom: 0; display: none; /*绝对定位到右下角*/ } kbd:hover>button{ display: inline-block; /*鼠标浮到kbd上才出现*/ }
box-shadow
使用指南inset
默认阴影在边框外。
使用inset后,阴影在边框内(即便是透明边框),背景之上内容之下。web
<offset-x> <offset-y>
<blur-radius>
<spread-radius>
<color>
最经常使用的是后五个值,例子:数组
/* offset-x | offset-y | color */ box-shadow: 60px -16px teal; /* offset-x | offset-y | blur-radius | color */ box-shadow: 10px 5px 5px black; /* offset-x | offset-y | blur-radius | spread-radius | color */ box-shadow: 2px 2px 2px 1px rgba(0, 0, 0, 0.2); /* inset | offset-x | offset-y | color */ box-shadow: inset 5em 1em gold; /* Any number of shadows, separated by commas */ box-shadow: 3px 3px red, -1em 0 0.4em olive;
//遍历keys,生成kbd标签 var index = 0; while (index< keys['length']){ var divxxxx = document.createElement('div'); mainxxxx.appendChild(divxxxx); row = keys[index]; index2 = 0; while (index2<row.length){ kbdxxxx = document.createElement("kbd"); kbdxxxx.textContent = row[index2]; divxxxx.appendChild(kbdxxxx); index2++; } index++; }
这个hash容纳你所须要的全部细节:
例如altkey
能够看出你再按m的时候是否同时按了alt浏览器
//监听键盘被按事件 document.onkeypress = function (sjdhfakdhjlsdka) { //sjdhfakdhjlsdka这个参数 包含你想要知道的全部信息,是一个hash key = sjdhfakdhjlsdka['key'];//获得用户的键 website = hash[key];//获取网站地址 // location.href = 'http://'+website;//将键变成新的网站的地址 //location.href当前地址栏.地址 // window.open('http://'+website,"_blank"); //window.open 窗口.打开 "_blank"新窗口打开. }
//每个kbd里面加入button buttonxx = document.createElement("button"); buttonxx.textContent = "编辑"; // 每个button的id都是row[index2],即kbd里面的内容,以便区分 buttonxx.id = row[index2]; //添加button点击事件 buttonxx.onclick = function (jfglkhj) { //☆☆☆☆这里不能用this,也不能用buttonxx,由于buttonxx只是一个容器,每一次循环,里面放的东西都不同 // 最后他里面放的东西是最后那个createElement("button").因此不行 //例如 // console.log(buttonxx); // 无论按那个键,全部的打印出来的都是最后一个button //解决方法:使用 jfglkhj.target ,指的就是当前完整元素. // 例如: // console.log(jfglkhj); //console.log(jfglkhj.target); // console.log(jfglkhj.target.id); key = jfglkhj.target.id;//好比说v //或者jfglkhj['target']['id']; x = prompt('给我一个网址');//好比说mtt.com hash[key] = x;//赋值 }; kbdxxxx.appendChild(buttonxx);
若是使用buttonxx缓存
使用console.log(jfglkhj.target);cookie
console.log(jfglkhj.target.id);
没有办法让js变量在下一个页面出现,没法改变js源代码.只能把hash这个变量存到js以外的地方.
问题解决思路:
每次变动hash就找一个地方备份,下次刷新,就覆盖原来的hash
一变就存,一刷新就覆盖.
查看localStorage
localStorage,只要编辑了,我就存
x = prompt('给我一个网址');//好比说mtt.com hash[key] = x;//赋值 // 问题:刷新以后编辑的网址没有了 // 解决方法:使用localStorage,只要变就备份,只要刷新就覆盖 //若是hash变动,只要编辑了,我就存 localStorage.setItem("zzz",JSON.stringify(hash));//JSON.stringify(hash)把hash变成字符串,存到zzz变量里备份 //上面这句代码的做用:localStorage里有不少桶,吧hash存到zzz这个桶里 //每一次编辑,就把新的hash存到 浏览器里 //而后把这个浏览器里的hash覆盖原来的就能够了 //熟悉原理:一变动就存档
上面是备份hash代码
//把localStorage里hash,zzz拿出来 var hashINLocalStorage = JSON.parse(localStorage.getItem('zzz')|| 'null'); if(hashINLocalStorage){ //若是hashINLocalStorage不为空,第二次刷新就不为空了. hash = hashINLocalStorage;//覆盖hash }
上面是覆盖代码
位置:
经测试,缓存清空localStorage就没有了