前端导航站点总结

183 阅读1分钟

1.HTML

1.用了header、main,虽然用了这些,但是还是要加class,因为直接在标签上面写样式,可能误改,后面也不能加这样的样式了。

2.标签:global

2.CSS

1.初始化 reset

2.white-space: nowrap;不换行

3.移动端不加宽度,居中对齐用margin

4.引用字体图标

(1)网站:www.iconfont.cn/

(2)加入购物车,添加至项目

(3)点击Symbol,用这种方法,然后复制链接

然后插入到html里面

 <script src="//at.alicdn.com/t/font_2084480_lg1oebsr3ij.js"></script>

让项目里新增图标的时候,要更新这个链接

后面的操作看帮助

3.JS

1.离开页面时,把新的hashMap存入localStorage

window.onbeforeunload = () => {
    const string = JSON.stringify(hashMap)   //把对象转为字符串
    localStorage.setItem('hashMap', string)  
     //把字符串储存到 localStorage中,它只能储存字符串
}

2.把哈希值取出来

const x = localStorage.getItem('hashMap')  //把字符串取出来
const xObject = JSON.parse(x)  //把字符串转换为对象
**JSON.stringify( hashMap )   转换为字符串**
**JSON.parse( **hashMap** )  转换为对象**
**localStorage.setItem('hashMap', string)  储存到localStorage中,并命名为hashMap**
**localStorage.getItem('hashMap')   把字符串hashMap取出来**

3.slice  切

const animals = ['ant', 'bison', 'camel', 'duck', 'elephant'];
console.log(animals.slice(2));
 // expected output: Array ["camel", "duck", "elephant"]

切除数组,返回切好的数组

console.log(animals.slice(2, 4));
 // expected output: Array ["camel", "duck"]

两个参数,从哪里切,切到哪里

4.replace   替换

const simplifyUrl = (url) => {
    return url.replace('https://', '')
        .replace('http://', '')
        .replace('www.', '')
        .replace(/\/.*/, '')}

把URL里面的https://、http://、www.都替换成空字符串

把/后面的都切了,都替换成空字符串

$('.site_list').find('li:not(.addButton)').remove()

找出site_list里面所有里除了最后一个,(除了哪个,把哪个的类名写里面),都删除了

.insertBefore($lastLi)

添加到lastLi前面

6.不用a做跳转

$('li:not(.addButton)').on('click', () => {
            window.open(node.url)
  })
 e.stopPropagation();//阻止冒泡
hashMap.splice(index, 1) 把hashMap数组,从index开始,删除一个,就是删除下标为index的那一个

8.indexOf()

url.indexOf('http') !== 0

从url里面找http,查找到字符串,返回第一次出现的索引,如果没有找到,则返回 -1