1. 程式人生 > 實用技巧 >小知識總結

小知識總結

淘寶的viewport

HTML:meta viewport 
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no,viewport-fit=cover">

CSS: css reset

*{box-sizing: border-box;}
*::before, *:after{box-sizing: border-box;}
*{margin: 0; padding: 0;}
ul,ol{ list-style: none;}
a{color: inherit; text-decoration: none;}
img{max-width: 100%;max-height: 100%;}

css 塊元素命名要注意避坑

text-transform: uppercase  //轉換大寫


    margin-left: auto;
    margin-right: auto;    //如果一個元素他的最大寬度固定或寬度固定  用這兩行程式碼來居中

JS

  • JSON.stringify(物件)把物件變成字串,序列化;
  • JSON.parse(字串)把字串變回物件,反序列化
  • typeOf xxx === 'string'用於xxx的非物件的檢測
  • xxx instanceof Array用於判斷xxx的物件的檢測
  • 析構賦值
const {response}=request
//等同於
const response = request.response
  • indexOf是查某個指定的字串在字串首次出現的位置(索引值) (也就是從前往後查)
  • lastIndexOf是從右向左查某個指定的字串在字串中最後一次出現的位置(也就是從後往前查)
  • .toUpperCase() 轉換大寫
e.stopPropagation() //阻止冒泡