Warning: error_log(/data/www/wwwroot/hmttv.cn/caches/error_log.php): failed to open stream: Permission denied in /data/www/wwwroot/hmttv.cn/phpcms/libs/functions/global.func.php on line 537 Warning: error_log(/data/www/wwwroot/hmttv.cn/caches/error_log.php): failed to open stream: Permission denied in /data/www/wwwroot/hmttv.cn/phpcms/libs/functions/global.func.php on line 537 黄色永久网站,亚洲国产美女视频,97在线视频观看

          整合營銷服務商

          電腦端+手機端+微信端=數據同步管理

          免費咨詢熱線:

          css基礎快速入門-14偽類first-letter

          學生就可以看懂的css基礎實戰系列,pre標簽里是筆記總結,動手實際操作一下會加強理解。有疑問留言交流哦。

          可能比較枯燥,但是再堅持一下,前端知識的大門就會大開了。

          tml和css的使用方法以及樣式,很好的基礎知識系列,內容都是干貨知識點,適合收藏下來!


          布局步驟

          第一步: 清除默認樣式

          第二步: 劃分模塊

          第三步: 設置模塊的大小以及位置

          第四步: 劃分下一級模塊

          html和css

          引入網頁頭像

          <link rel="shortcut icon" href="img/...ico">

          css樣式表的引入方式

          css樣式表的引入方式

          1、外鏈式

          <link href="" rel="stylesheet">

          2、嵌入式

          <style></style>

          3、行內樣式

          <div style="width:200px;height:200pxs;"></div>

          1. @import url('')


          文件命名以及變量命名

          命名規范

          1、嚴格區分大小寫

          2、可以采用字母數字下劃線$,數字不開頭

          3、命名語義化

          4、可以采用駝峰命名法

          清除默認樣式

          清楚邊距

          *{

          margin: 0;

          padding: 0;

          list-style: none;

          }

          a標簽清楚下劃線和顏色

          a{

          color: black;

          text-decoration: none;

          }

          css中顏色的表示方式

          css中顏色的表示方式:

          1.預定義的顏色【關鍵字顏色】 red pink blue yellow

          2.#6位數的色值 #00-00-00 紅綠藍

          3.rgb(紅,綠,藍) :rgb([0-255],[0-255],[0-255])

          4.rgba(red,green,blue,透明度) :rgba([0-255],[0-255],[0-255],[0-1])

          0-1: 0全透明,1不透明

          html中的標簽和屬性


          html:

          標簽:

          按照語法分類:

          1.單標簽:只有開始標簽

          meta img a

          2.雙標簽:有開始標簽和結束標簽

          <html></html>

          3.屬性的語法

          語法:

          屬性名 = "屬性值"

          屬性名 = "屬性值1 屬性值2"

          注意:

          1、標簽名和屬性名之間要有空格

          2、多個屬性之間要有空格

          3、多個屬性值之間要有空格

          4.開始標簽 標簽名后有空格

          ?


          按照標簽在頁面中的呈現效果分類:

          1、行內元素

          行內元素定義:在一行內顯示,只能設置左右間距,不可以設置上下間距。

          舉例:span del i em b strong a(title="鼠標移入時顯示的文字";target=" "(新窗口打開的位置 _self:在本窗口打開;_blank:在新窗口打開) ...

          2、塊元素

          塊元素定義:可以設置寬高,獨占一行。

          舉例:div 標題標簽 列表標簽 段落標簽 ...

          3、行內塊元素

          行內塊元素定義:可以設置寬高,在一行顯示。

          舉例:img 【title="鼠標移入時顯示的文字" 】 表單控件

          元素的轉換

          塊元素: display:block;

          行內塊元素:display:inline-block;

          行內元素: display:inline;


          元素的級別

          塊元素 > 行內塊元素 > 行內元素

          元素嵌套規范

          1、同一級別可以相互嵌套

          2、級別高的元素可以嵌套級別低的元素

          3、段落標簽只能嵌套行內元素

          4、a標簽不可以嵌套a標簽;p不能嵌套p

          盒子模型及其問題

          四部構成:

          1、margin 外間距 盒子與盒子之間的距離

          2、border 邊框

          3、padding 內填充(內間距) 邊框與內容之間的距離。

          4、content 內容

          margin-top margin-right margin-bottom margin-left

          margin: 50px; 上 右 下 左

          margin: 50px 100px; 上下 左右

          margin:0 auto; auto自動

          margin: 50px 100px 150px; 上 左右 下

          margin: 50px 100px 150px 200px; 上 右 下 左

          border: 1px solid red;

          border-top \ border-right \border-bottom \ border-left

          border-top-width:上邊框的寬度

          ?

          padding:設置方法同margin

          ?

          content: ;

          width : 數值 百分比 auto

          height: 數值 百分比 auto

          ?


          盒子模型的問題:

          1.大部分元素的marginpadding默認為0,但有一部分的marginpadding不為0,例如body 標題標簽(h1-h6)(ul ol il等列表標簽) 段落標簽

          2.想領的兩個塊元素的margin會重合,值會取最大值

          3.margin可以為[負數] ,padding不可以設置[負數]。

          4.行內元素margin只有左右,沒有上下

          5.如果(1)發生嵌套關系的元素,(2)父元素沒有上邊框,(3)上padding ,(4)父元素與子元素之間沒有別的內容,此時子元素margin-top就會作用到父元素身上

          margin-top的解決方式:

          1.用父元素的padding-top代替子元素的margin-top;

          2.給父元素添加overflow:hidden;

          寬高的設置和計算

          height:auto / 百分比 / px;

          width:auto / 百分比 / px;

          height:auto; 參照與父元素

          width:auto;參照與內容

          box-sizing:border-box; 將邊框算入盒子內;

          ?

          一個元素實際的寬高

          實際寬度 = border-left + padding-left + width +paddint-right + border-right;

          實際高度 = border-top + padding-top + height + padding-bottom + border-bottom;

          浮動

          作用:讓塊元素橫排排列

          樣式: float:left;從左往右排列

          float:right;從右往左排列

          原理:讓元素脫離文檔流,讓元素從文檔層浮動到浮動層。

          引發的問題:父元素不設置高度,子元素都浮動,浮動的子元素撐不開父元素。(浮動的元素脫離文檔流)

          *解決方式一:給父元素添加 overflow:hidden;(超出部分隱藏)

          *解決方式二:在父元素內容最后添加擁有清除浮動屬性的元素。

          clear:right/left/both ; 別的浮動對它的影響清除掉

          例:

          .box:after{

          content: "";

          display:block;

          width: 0;

          height: 0;

          clear:both;

          }

          *解決方式三:父元素能設置高度的盡量設置高度

          浮動之后的塊元素參照內容:屬性值 auto

          定位

          定位的元素脫離文檔層,到達定位層

          定位的元素會多出5個樣式:

          top right bottom left z-index:999

          上 右 下 左 層級(層級越高,離用戶越近)【只能在有定位屬性的元素上才能用】

          層級:

          z-index:整數;

          定位的幾種方式:

          1.相對定位:

          相對于自身來定位,在文檔層中保留原來的位置

          用法:

          position:relative;

          2.絕對定位:

          相對于最近的 定位的 祖先元素 來定位,完全脫離文檔流(其他頂替其位置)

          用法:

          position:absolute;

          +方向值

          3.固定定位:

          相對于瀏覽器的四條邊,完全脫離文檔流

          用法:

          position:fixed;

          top與bottom同時定義,那個樣式會作用到元素身上的判斷關系:

          top的權重比bottom的權重大

          left的權重比right的權重大

          元素作用時:

          1.如果是

          position:relative;

          left:;

          margin:;

          先作用margin,在作用relative;

          2.如果是

          position:absolute;

          left:;

          margin:;

          先作用absolute,在作用margin;

          定位元素的居中方式:

          方法一:

          1.水平居中:

          position:absolute;

          left:50%;

          margin-left:-自身長度的一半;

          2.垂直居中:

          position:absolute;

          top:50%;

          margin-top:-自身長度的一半;

          3.絕對居中:

          position:absolute;

          left:50%;

          top:50%;

          margin-left:-自身長度的一半;

          margin-top:-自身長度的一半;

          方法二:

          1.水平居中:

          position:absolute;

          left:0;

          right:0

          2D和3D

          2D和3D屬性:

          1.平移樣式

          transform:translate(x,y); 向上為負, 向下為正

          transform:translateX(100px);

          transformrotate(180deg) ; (1turn)轉一圈

          平移 transform:translate() 例子:translatexytranslateX()

          旋轉 transform:rotate() 例子rotate(180deg)順時針 -180deg 逆時針

          transformrotate()空格translate();

          transform-origin:px px;變換的中心點;

          left center

          縮放 transform:scale() 例子:scale(2) 放大為原來的2倍 scale(0.n)縮小為原 來的0.n scalemnxmyn

          斜切 transform:skew() 例子:skew(45peg) 左拉伸45° skew(45pegm

          1. 過渡transition
          2. transition:all 0.5s;

          全部 時間

          3.過渡的屬性樣式: transition-property: , ;

          可以為:屬性的全部樣式

          4.過度的總時間: transition-duration:;

          5.過渡的時間函數: transition-timing-function:;

          linear(勻速) ease(開頭結尾慢,中間快)

          cubic-bezier(1,0.07,0.54,0.21) 貝塞爾曲線

          6.延遲 transition-delay:;

          ?

          3d效果:和2d的一樣transition,transform;

          prespective:給父元素加prespective(滅點的值)

          prespective-origin:x y;滅點的位置 調整觀察的角度(大多數情況不設置)

          transform:ratate3d(0-1的值,0-1的值,0-1的值,45deg)

          transform:ratateY(45deg)

          transform:translate3d(0-1,0-1,px)

          ?

          父元素:transform-style:preserve-3d;

          動畫

          動畫規則:

          @keyframes 動畫名(隨便給){

          (動畫規則)

          from{}

          to{}

          }

          @keyframes 動畫名(隨便給){

          (動畫規則)

          0%{}

          50%{}

          100%{}

          }

          @keyframes animation1{

          from{

          background-color:red;

          }

          to{

          background-color:blue;

          }

          }

          ?

          掛載動畫:將動畫加到元素身上

          .元素{

          animation:animation1 時間 步數 時間函數 延遲時間 次數 ;

          }

          掛載多個動畫:

          .元素{

          animation:animation1 時間,animation2 時間,animation1 時間;

          其他動畫的相同的可以附件通過animation屬性;

          }

          animation的樣式

          動畫名:animation-name

          時間: animation-duration

          步數:animation-steps:8;

          時間函數:animation-timing-function

          延遲: animation-delay

          動畫次數: animation-iteration-count:infinite(無限次)/2;

          指定下一次動畫是否逆向:animation-direction:alternate(逆向)/ normal(常規);

          最后的狀態:animation-fill-mode:backwards(默認(保持一開始的狀態))/forwards(保持當前的狀態);

          狀態即指定動畫是否運動: animation-play-state: running(運行)/paused(靜止);

          ?

          元素分類

          按照在頁面中的呈現效果:

          1.行內元素:在一行內顯示 ,不可以設置寬高 :(存放文字)

          span a b i strong del

          2.行內塊元素:在一行內顯示,可以設置寬高:(有縫隙 不常用)

          img 表單控件

          3.塊元素 :可以設置寬高,獨占一行

          div 標題標簽(h1-h6) 列表標簽(ul-li ol-li dl>dt+dd 段落標簽 (p pre))

          元素嵌套規范:

          1.同一級別可以相互嵌套

          2.級別高的可以嵌套級別低的元素

          3.p標簽只能嵌套行內元素

          4.a鏈接不能相互嵌套

          元素的轉換:

          1.塊元素:display:block;

          2.行內塊元素:display:inline-block;

          3.行內元素:display:inline

          背景圖片以及瀏覽器內核

          背景圖

          先設大小,在引background;

          background: url('路徑') no-repeat left bottom/contain;

          //圖片位置 禁止重復 位置(top bottom left right)

          1. 路徑:background-image:url(“”),url(“”);加載多張背景圖
          2. 背景圖大小: background-size:100px auto,100px auto; 會重復
          3. 背景的圖重復:

          4. background-repeat:no-repeat,repeat;(無重復)

          5. background-repeat:repeat-x(x方向重復)

          background-repeat:repeat-y(y方向重復)

          1. 背景圖的位置:


          background-position:x y;(數值 方位值(top/bottom left/rightcenter(可以省略)) )

          1. 背景開始渲染的位置: background-origin: ;


          8. padding-box;(默認)從padding位置開始渲染

          9. border-box;從邊框的位置開始渲染

          content-box;從內容的位置開始渲染

          1. 圖片結束渲染的位置:background-clip: ;


          11. padding-box;(默認)從padding位置結束渲染

          12. border-box;從邊框的位置結束渲染

          content-box;從內容的位置結束渲染

          1. 使得背景圖加載到瀏覽器中
          2. background-attachment: fixed;

          8.可以簡寫:

          background:空格隔開;

          1. 背景圖漸變
          2. background: linear-gradiend(top,顏色1,顏色2,顏色n)

          //漸變開始的方向(默認top) 類似25deg(25度)

          10.瀏覽器內核//背景色漸變

          1. /* 標準語法 */

          例子:background: linear-gradient(top,#3bbcff,#47eaff);

          2. /* 谷歌內核 -webkit- */

          例子:background: -webkit-linear-gradient(top,#3bbcff,#47eaff);

          3. /* 火狐內核 -moz- */

          例子:background: -moz-linear-gradient(top,#3bbcff,#47eaff);

          4. /* 歐鵬內核 -o- */

          例子:background: -o-linear-gradient(top,#3bbcff,#47eaff);

          5. /* IE內核 -ms- */

          例子:background: -ms-linear-gradient(top,#3bbcff,#47eaff);

          ?

          文件的讀取方法路徑

          絕對路徑:從盤符開始的一條完整路徑

          相對路徑:兩個文件的位置關系

          邊框的相關屬性【圓角,邊框形狀】

          border-radius:邊框的半徑 設置圓角 n%或者num像素

          border-style:dotted solid double dashed;

          上邊框是點狀

          右邊框是實線

          下邊框是雙線

          左邊框是虛線

          透明度

          透明性的選擇:(整個容器都變)

          opacity:;0-1之間的值;

          字體

          font-family =“ 字體” //字體樣式可以被繼承

          鼠標移入樣式

          span標簽

          cursor:pointer; 鼠標樣式:手型

          陰影

          box-shadow:x軸偏移量 y軸偏移量 陰影的模糊程度 陰影的大小(0和本身一樣大小) 陰影的顏色;

          引入字符圖標

          引入字符圖標:

          行內元素 隨意

          span class=“iconfont 圖標類名”

          可調節樣式: 同文字

          文檔流

          文檔流:

          標準情況下 ,頁面元素從左往右 從上往下 依次排列

          flex布局(規范的設計稿)-彈性布局

          容器(父元素)的屬性:【display:flex;】

          *flex-direction: 決定主軸方向。

          row 主軸在水平方向,從左向右(默認)。

          row-reverse 主軸在水平方向,從右向左

          column 主軸在垂直方向,從上到下

          column-reverse 主軸在垂直方向,從下到上

          *flex-wrap: 決定項目換行

          wrap: 項目換行

          nowrap: 項目不換行(默認值)

          wrap-reverse: 項目換行且反轉

          *justify-content: 決定項目在主軸的對齊方式

          flex-start;主軸的起點

          flex-end;主軸的終點

          center;主軸的中心

          space-between;兩端對齊

          space-around;項目兩側距離相等

          *align-items:項目在交叉軸上的對齊方式(適用于一根軸線與多跟軸線)

          flex-start:交叉軸的起點

          flex-end:交叉軸的終點

          Center:交叉軸的中心

          baseline: 基線對齊(文本底部)

          *align-content:定義項目在交叉軸上的對齊方式(僅適用于多根軸線)

          flex-start;交叉軸的起點

          flex-end;交叉軸的終點

          center;交叉軸的中心

          space-between;兩端對齊

          space-around;兩側距離相等

          子元素(項目)的屬性:

          *order:定義項目的排列順序,數值越小,越靠前,默認值為0(可以取負值)。

          *flex-grow:定義項目的放大比例。默認值為0,即使存在剩余空間,也不放大。

          *flex-shrik:定義項目的縮小比例,默認值為1,空間不足,項目縮小;值為0時,空間不足,項目也不縮小.

          *flex-basis: 定義項目占據的主軸空間.默認auto或者自己添加像素;

          *align-self:定義單個項目在交叉軸的對齊方式.

          flex-start:交叉軸的起點

          flex-end:交叉軸的終點

          Center:交叉軸的中心

          滾動條

          overflow-x:auto;超出部分在x軸的表現形式。

          auto:自動;(如果超出,就自動以滾動條的形式顯示)

          去滾動條: 加在具有overflow屬性的元素身上

          ::-webkit-scrollbar{

          height:0;

          }

          overflow-x: visible|hidden|scroll|auto|no-display|no-content;

          值 描述 測試

          visible 不裁剪內容,可能會顯示在內容框之外。 測試

          hidden 裁剪內容 - 不提供滾動機制。 測試

          scroll 裁剪內容 - 提供滾動機制。 測試

          auto 如果溢出框,則應該提供滾動機制。 測試

          no-display 如果內容不適合內容框,則刪除整個框。 測試

          no-content 如果內容不適合內容框,則隱藏整個內容。 測試

          ?

          輪播圖

          swiper(.js).com

          表格

          [行] [列]

          ?

          table身上的屬性

          table身上的屬性:

          border:表格邊框 cellspacing:單元格間的間距

          cellpadding:單元格的內容與其邊框的內邊距

          bgcolor:表格的背景顏色 background:表格的背景圖片

          width:表格寬度 height:表格高度

          border-collaspe:collaspe:邊框合并,不疊加 cellspacing:0:邊框合并,但合并之后的邊框寬度等于 前兩個邊框寬度之和

          caption:表格標題

          background:表格背景圖

          cellspacing:單元格之間的間隙寬度

          align:表格的水平對齊方式,通常是left,center,right

          表格的標題

          <caption align="水平對齊方式" valign="標題與表格的相對位置"></caption>

          單元格【tr】【td】

          width:單元格寬度height:單元格高度

          align:單元格內文本的對齊方式,通常是左,中,右 left,center,right

          valign:單元格內文本的對齊方式,通常是上,中,下 top,middle,bottom

          nowrap:在為設置單元格寬度時,當文本長度寬于單元格寬度,將要換行時,該標簽會使其不換行

          ?

          <tr align="center" valign="bottom">

          <td align="center" nowrap>手機空中免費充值</td>

          <td width="100px">IP卡</td>

          <td width="100px" bgcolor="#006400" valign="top">網游</td>

          </tr>

          表格的跨行與跨列【td】

          rowspan:跨行標簽,表示跨了多少行

          colspan:跨列標簽,表示跨了多少列

          表格標簽拓展及其屬性

          thead:定義表格的表頭。

          tbody:定義表格主體(正文)。

          tfoot:定義表格的頁腳(腳注或表注)。

          colgroup:標簽用于對表格中的列進行組合,以便對其進行格式化。

          注意:不管thead、tbody、tfoot的代碼先后順序如何,html顯示時,始終是先顯示thead,再顯示tbody,最后顯示tfoot。

          1、<thead> 內部必須擁有 <tr> 標簽!

          2、<tfoot> 元素內部必須包含一個或者多個 <tr> 標簽。

          3、<tbody> 元素內部必須包含一個或者多個 <tr> 標簽。

          4、必須在 table 元素內部使用這些標簽。

          5、當不同行間的單元格合并時各單元格所在的行不要加tbody標簽。

          標題欄

          《tr》<th></th>《/tr》 用法和td相似 知識自動將單元格內容以粗體顯示

          表單控件表單標簽

          <form action=" " method=" ">

          action:表單信息提交的位置;

          method:提交的方式

          get:地址欄,信息量少,安全性低

          post:信息量多,比較安全

          1.輸入文本【輸入框】:

          用戶名:<input type="text" placeholder="請輸入用戶名" maxlength="10" value=" " name="username" class="">

          placeholder:默認提示文本;

          maxlength:規定輸入的最大字符數

          name:本文本框的名字,與后臺進行數據交互用

          class:定義本文本框的樣式,相當于盒子

          placeholder下的縮進

          text-indent:2em;縮進

          2.輸入密碼【密碼框】:

          密碼:<input type="password" placeholder="請輸入密碼" maxlength="10" value=" " name="psw" class="">

          3.單選按鈕[name的值必須相同]:

          請選擇你的性別:

          <label for="man"> [label實現點什么就選中 ,for中的值和id中的值相同]

          男:<input type="radio" name="sex" id="man" checked> //checked默認選項

          </label>

          <label for="woman">

          女:<input type="radio" name="sex" id="woman">

          </label>

          4.多選按鈕[name的值必須相同]:

          請選擇你喜歡的音樂:

          搖滾:<input type="checkbox" checked>

          搖滾:<input type="checkbox" checked>

          搖滾:<input type="checkbox" checked>

          5.下拉列表【下拉框】:

          選擇你的學歷:

          <select name="" id="">

          <option value="">學士</option>

          <option value="">博士</option>

          <option value="">碩士</option>

          </select>

          6.上傳文件:

          選擇你的照片:

          <input type="file">

          7.留言文本空間:

          <textarea name="" id="" rows="" col="">

          </textarea>

          8.用戶是否允許重新設置textarea大小css屬性:

          resize: none/both/vertical/horizontal;不允許/上下允許拖動/只能在垂直方向拖動/只能在水平方向 拖動

          9.重置按鈕:

          <input type="reset">

          10.提交按鈕:

          <input type="submit">

          11.自定義按鈕:

          <input type="button" value="按鈕">

          <button>搜索</button>

          12.顏色:

          <input type="color">

          13.時間日期:

          年月:<input type="month">

          年周:<input type="week">

          時分:<input type="time">

          年月日:<input type="date">

          年月時分:<input type="datetime-local">

          14.驗證

          <input type="email"> 郵箱驗證

          <input type="tel" autofocus> 電話

          15. autofocus 自動獲取焦點

          </form>

          文本模型

          文本換行

          使非中日韓文本換行

          word-break: break-all ;

          文本禁止換行

          white-space:nowrap;

          單行文本溢出部分以省略號顯示

          overflow: hidden;(放文本的容器)

          text-overflow: ellipsis;

          多行文本溢出

          1. 指定為彈性盒子
          2. display: -webkit-box;
          3. 在彈性盒模型中指定元素的排列順序
          4. -webkit-box-orient: vertical;
          5. 指定文本顯示(溢出)的行數;
          6. -webkit-line-clamp: 3;
          7. height要是line-height的倍數
          8. line-height: 70px;
          9. overflow:hidden;

          音頻視頻標簽

          音頻標簽

          <audio src="" controls loop autoplay></audio>

          controls 空間向用戶顯示:

          loop 循環播放

          autoplay當前頁面加載完自動播放

          視頻標簽

          <video src="" controls loop autoplay></video>

          H5語義化標簽

          <header>頭部</header>

          <nav>導航</nav>

          <aside>側導航<aside>

          <section>頁面中的某一部分</section>

          <main>主體</main>

          <footer>底部</footer>

          meta標記【簽】

          name="關鍵字" cantent="內容"

          <mate http-equiv="Refresh" content="10";url="跳轉路徑"> //每10s刷新一次并且跳轉到跳轉路徑知識的文件

          bgsound標簽

          <bgsound src="路徑" loop="播放次數">

          body屬性

          1. bgcolor:背景顏色
          2. background:背景圖片
          3. text:文檔中文字的顏色
          4. link:超鏈接的顏色
          5. alink:正在訪問的超鏈接的顏色
          6. vlink:已訪問過的超鏈接的顏色
          7. leftmargin/rightmargin/topmargin/bottommargin: 左/右/上/下邊距的像素值

          對文字操作的標簽

          1. <p></p>開始一個新段落,可單可雙
          2. 換行標簽,單獨標記
          3. <pre></pre>預格式化【敲什么樣式,顯示什么樣式】
          4. <font></font> 用來設置文字的字體 大小 顏色 粗細等
          5. 文字樣式標記[均成對出現]
          6. b 粗體 i 斜體 u 下劃線 tt 等寬
          7. sup 上標體 sub 下表體 strike 刪除線 big 大號字樣
          8. small 小號字樣 blink 閃爍字樣 em強調字樣 strong著重字樣 cite引用字樣

          列表標簽

          1. 符號列表
          2. <ul type="circlr(空心圓點)/disc(實心圓點)【默認】/square(實心方塊)">

          2. <li>

          <li>

          </ul>

          1. 排序列表
          2. <ol type="1(數字) /a(a,b,c..)/ A(A,B,C...)/ i(i,ii,iii,...)/ I(I,II,III,...)">

          4. <li>

          <li>

          </ol>

          a標簽

          <a href="路徑 " title="鼠標移入時顯示的文字" target=" "(新窗口打開的位置 _self:在本窗口打開;_blank:在新窗口打開;_parent:在當前窗口的父窗口打開鏈接;_top:在整個瀏覽器窗口打開) ...

          [字符實體]常用的轉義字符

          顯示結果 描述 實體名稱

          空格

          < 小于號

          大于號

          & 和號

          " 引號

          ' 撇號 (IE不支持)

          ¢ 分(cent)

          £ 鎊(pound)

          ¥ 元(yen)

          € 歐元(euro)

          § 小節

          ? 版權(copyright)

          ? 注冊商標

          ? 商標

          × 乘號

          ÷ 除號

          選擇器

          分類

          css選擇器

          1.通用選擇器:

          *{}//選擇所有的標簽

          2.群組選擇器:

          E1,E2,E3..{}//選擇E1 E2 E3

          3.標簽選擇器

          標簽名{}

          4.類名選擇器:

          .類名{}

          5.后代選擇器

          .E1 .E2{} //選擇E1 的后代E2

          6.交叉選擇器

          標簽名.類名{}

          7.id選擇器

          例如 創建id

          <div id=“box”></div>

          #id名{} //選擇頁面中id為**的標簽

          8.偽類選擇器:

          鼠標移入狀態

          Ehover{ } E元素選擇鼠標移入狀態

          Ehover .子類{ } 選擇e元素下鼠標移入時子類的變化

          獲取焦點,用于表單的輸入

          E: focus{

          outline: none;

          }

          9.偽結構選擇器:

          E:first-child{} 作為子元素的第一個孩子的E標簽

          E:last-child{} 作為子元素的最后第一個孩子的E標簽

          E: nth-child(n){} //作為子元素的第n個孩子的E標簽

          E: nth-last-child(n) 作為子元素的倒數第n個孩子的E標簽

          E:first-of-type{} 作為子元素的同類型的第一元素

          E:last-of-type{} 作為子元素的同類型中的最后一個元素

          E: nth-of-type(n) 作為子元素的同類型中的第n個元素

          E: nth-last-of-type(n) 作為子元素的同類型中的倒數第n個元素

          (n)n可以以為num/even(偶數)/odd(奇數)/3n(3的倍數)

          例子:5.15/偽結構選擇器

          10.偽元素選擇器:

          ::after{} 在元素之后加入一個

          ::before{

          content:“內容之前”;

          color:;

          } 在元素之前

          屬于行內元素

          ::after{} ::before{}偽元素 content:""; 樣式必須寫

          ?

          11.子類選擇器

          相鄰兄弟選擇器

          E1+E2{} 選擇E1的下一個兄弟元素E2(不能選中上一個兄弟元素)

          div.box>a+img a和img統計

          子類選擇器

          E1>E2{} 選擇E1的子類元素E2

          例子:div.box>div.item{$}*20

          div.box>a>img

          12.屬性選擇器

          [屬性名]{} 選擇所有擁有屬性為 屬性名 的元素

          [屬性名=“value”]{} 選擇擁有屬性名的屬性 且屬性值為value

          E[屬性名=“value”]{} 選擇擁有屬性名的屬性 且屬性值為valueE元素

          E[屬性名~=“value”]{} 選擇擁有屬性名的屬性 并且屬性值一個或者多個,其中一個屬性值為valueE元素

          E[value^=“1”]{} 選擇擁有 value的屬性 并且屬性值一個或者多個,其中一個屬性值以 1 開頭的E元素

          E[value$=“1”]{} 選擇擁有 value的屬性 并且屬性值一個或者多個,其中一個屬性值以 1 結尾的E元素

          E[value*=“1”]{} 選擇擁有 value的屬性 并且屬性值一個或者多個,其中一個屬性值包含 1 的E元素

          例子:屬性選擇器

          選擇器的優先級

          宗旨:越具體的優先級越高

          id (100 ) > class( 10 )> 標簽名( 1)

          .box .son{ } 10+10=20

          abcde優先級(e為個位):

          a:行內樣式

          b:id選擇器

          c:類名選擇器 偽類選擇器(:hover) 屬性選擇器

          d:標簽選擇器 偽元素選擇器 (::after)

          e:通用選擇器有一個

          選擇有中有一個abcde在其位置+1

          移動端布局步驟

          1. 修改視口
          2. <meta name="viewport" content="width=device-width">

          ?

          視口:視覺視口,布局視口,理想視口

          em:當前字體的倍率 100px=10em

          rem:html字體的倍率

          移動端窗口 375*667

          html{

          font-size:0.5rem;

          }

          .box{

          width: 750rem; //375px=750rem*0.5px ; 100px=1rem

          height: 1334rem;

          }

          1. 引入rem.js
          2. <script src="路徑"></script>
          3. 修改rem.js中設計稿的寬度
          4. 100px=1rem

          我是一名前端開發程序員,自己整理了一份2019最全面前端學習資料,從最基礎的HTML+CSS+JS到移動端HTML5到各種框架都有整理,送給每一位前端小伙伴,這里是小白聚集地,歡迎初學和進階中的小伙伴

          前端資料獲取方式:

          1.在你手機的右上角有【關注】選項,點擊關注!

          2.關注后,手機客戶端點擊我的主頁面,右上角有私信,請私信回復:【學習】

          電腦已經設置好了關鍵詞自動回復,所以回復的時候請注意關鍵詞喲~

          avaScript 是一門弱類型語言,它對類型是弱校驗,正因為這個特點,所以才有了TypeScript這個強類型語言系統的出現,來彌補類型檢查的短板。TypeScript在實現類型強校驗的同時,還要滿足 JavaScript 靈活的特點,所以就有了類型兼容性這個概念。了解類型兼容性可以避免在實際的開發中出現一些低級錯誤。下面就來看看類型兼容性的概念和分類。

          1、類型兼容性的概念

          所謂的類型兼容性 用于確定一個類型是否能賦值給其他類型 。TypeScript中的類型兼容性是 基于結構類型 的,結構類型是一種只使用其成員來描述類型的方式。其基本原則是, 如果 x 要兼容 y,那么 y 至少要具有與 x 相同的屬性。

          下面來看一個例子,構建一個 Teacher 類 ,然后聲明一個接口 Student,Student 的屬性 Teacher 都有,而且還多了其他的屬性,這種情況下 Student 就兼容了 Teacher:

          <pre class="prettyprint hljs cs" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">class Teacher {
              constructor(public weight: number, public name: string, public job: string) {
          
              }
          }
          interface Student {
              name: string
              weight: number
          }
          let x: Student;
          x = new Teacher(120, 'TS', 'teacher') // :white_check_mark:</pre>
          

          如果反過來,Teacher 并沒有兼容 Student,因為 Student 的屬性比 Person 少一個。

          2、特殊類型的類型兼容性

          先來看看 TypeScript 中一些特殊類型的類型兼容性。

          (1)any

          any 類型可以賦值給除了 never 之外的任意其他類型,反過來其他類型也可以賦值給 any。也就是說 any 可以兼容除了 never 之外的所有類型,同時也可以被所有的類型兼容。

          <pre class="prettyprint hljs typescript" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">let any: any;
          let a: number = any;       // :white_check_mark:
          let b: {} = any;           // :white_check_mark:
          let b: () => number = any; // :white_check_mark:</pre>
          

          (2)never

          never 類型可以賦值給任何其他類型,但不能被其他任何類型賦值。

          <pre class="prettyprint hljs javascript" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">let never: never = (() => {
            throw Error('never');
          })();
          
          let a: number = never;       // :white_check_mark:
          let b: () => number = never; // :white_check_mark:
          let c: {} = never;           // :white_check_mark:</pre>
          

          可以看到,這里將 never 類型賦值給了 number、函數、對象類型,都是沒有問題的。

          (3)unknown

          unknown 和 never 的特性是相反的,即不能把 unknown 賦值給除了 any 之外的任何其他類型,但其他類型都可以賦值給 unknown。

          <pre class="prettyprint hljs javascript" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">let unknown: unknown;
          const a: number = unknown;       // 不能將類型“unknown”分配給類型“number”。
          const b: () => number = unknown; // 不能將類型“unknown”分配給類型“() => number”。
          const c: {} = unknown;           // 不能將類型“unknown”分配給類型“{}”。</pre>
          

          可以看到,當把 unknown 類型賦值給 number、函數、對象類型時,都報錯了,這就是因為類型之間不能兼容。

          3、函數類型的類型兼容性

          函數的類型兼容性主要包括以下六個方面:

          (1)參數數量

          函數參數數量要想兼容,需要滿足一個要求:如果將函數 y 賦值為 x,那么要求 x 中的每個參數都應在 y 中有對應,也就是 x 的參數個數小于等于 y 的參數個數:

          <pre class="prettyprint hljs javascript" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">let x = (a: number) => 0;
          let y = (b: number, c: string) => 0;</pre>
          

          上面定義的兩個函數,如果進行賦值的話,來看下兩種情況的結果:

          <pre class="prettyprint hljs ini" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">y = x;  // :white_check_mark:</pre>
          

          將 x 賦值給 y 是可以的,因為 x 的參數個數小于等于 y 的參數個數,而至于參數名是否相同是無所謂的。

          而將 y 賦值給 x 就不可以了:

          <pre class="prettyprint hljs ini" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">x = y; // 不能將類型“(b: number, c: string) => number”分配給類型“(a: number) => number”。</pre>
          

          這里 y 的參數個數要大于 x,所以報錯了。

          (2)函數參數類型

          除了參數數量,參數的類型也需要對應:

          <pre class="prettyprint hljs javascript" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">let x = (a: number) => 0;
          let y = (b: string) => 0;
          x = y; // error 不能將類型“(b: string) => number”分配給類型“(a: number) => number”。</pre>
          

          可以看到,x 和 y 兩個函數的參數個數和返回值都相同,只是參數類型對不上,所以也是不行的。

          (3)剩余參數和可選參數

          當要被賦值的函數參數中包含剩余參數(…args)時,賦值的函數可以用任意個數參數代替,但是類型需要對應:

          <pre class="prettyprint hljs javascript" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">const getNum = (
            arr: number[],
            callback: (...args: number[]) => number
          ): number => {
            return callback(...arr);
          };
          getNum(
            [1, 2],
            (...args: number[]): number => args.length // 返回參數的個數
          );</pre>
          

          剩余參數其實可以看做無數個可選參數,所以在兼容性方面是差不多的。

          再來看一個可選參數和剩余參數結合的例子:

          <pre class="prettyprint hljs typescript" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">// 第二個參數callback是一個函數,函數的第二個參數為可選參數
          const getNum = (
            arr: number[],
            callback: (arg1: number, arg2?: number) => number 
          ): number => {
            return callback(...arr); // error 應有 1-2 個參數,但獲得的數量大于等于 0
          };</pre>
          

          這里因為 arr 可能為空數組,如果為空數組則…arr不會給callback傳入任何實際參數,所以這里就會報錯。如果換成return callback(arr[0], …arr)就沒問題了。

          (4)參數雙向協變

          函數參數雙向協變即參數類型無需絕對相同:

          <pre class="prettyprint hljs typescript" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">let funcA = function(arg: number | string): void {};
          let funcB = function(arg: number): void {};
          // funcA = funcB 和 funcB = funcA都可以</pre>
          

          這里 funcA 和 funcB 的參數類型并不完全一樣,funcA 的參數類型為一個聯合類型 number | string,而 funcB 的參數類型為 number | string 中的 number,這兩個函數也是兼容的。

          (5)返回值類型

          函數返回值的類型也是要對應的:

          <pre class="prettyprint hljs javascript" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">let x = (a: number): string | number => 0;
          let y = (b: number) => "a";
          let z = (c: number) => false;
          x = y; // :white_check_mark:
          x = z; // 不能將類型“(c: number) => boolean”分配給類型“(a: number) => string | number”</pre>
          

          這里 x 函數的返回值是聯合類型,既可以是 string 類型也可以是 number 類型。而 y 的返回值類型是 number 類型,參數個數和類型也沒問題,所以可以賦值給 x。而 z 的返回值類型 false 并不是 string 也不是 number,所以不能賦值。

          (6)函數重載

          帶有重載的函數,要求被賦值的函數的每個重載都能在用來賦值的函數上找到對應的簽名:

          <pre class="prettyprint hljs typescript" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">function merge(arg1: number, arg2: number): number; // merge函數重載的一部分
          function merge(arg1: string, arg2: string): string; // merge函數重載的一部分
          function merge(arg1: any, arg2: any) { // merge函數實體
            return arg1 + arg2;
          }
          function sum(arg1: number, arg2: number): number; // sum函數重載的一部分
          function sum(arg1: any, arg2: any): any { // sum函數實體
            return arg1 + arg2;
          }
          let func = merge;
          func = sum; // error 不能將類型“(arg1: number, arg2: number) => number”分配給類型“{ (arg1: number, arg2: number): number; (arg1: string, arg2: string): string; }”</pre>
          

          sum 函數的重載缺少參數都為string返回值為string的情況,與merge函數不兼容,所以賦值時就會報錯。

          4、枚舉的類型兼容性

          數字枚舉成員類型與數字類型是互相兼容的:

          <pre class="prettyprint hljs cmake" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">enum Status {
            On,
            Off
          }
          let s = Status.On;
          s = 1;
          s = 3;</pre>
          

          雖然 Status.On 的值是 0,但是因為數字枚舉成員類型和數值類型是互相兼容的,所以這里給s賦值為 3 是沒問題的。但是不同枚舉值之間是不兼容的:

          <pre class="prettyprint hljs thrift" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">enum Status {
            On,
            Off
          }
          enum Color {
            White,
            Black
          }
          let s = Status.On;
          s = Color.White; // 不能將類型“Color.White”分配給類型“Status”。</pre>
          

          雖然 Status.On 和 Color.White 的值都是 0,但它們是不兼容的。

          字符串枚舉成員類型和字符串類型是不兼容的:

          <pre class="prettyprint hljs rust" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">enum Status {
            On = 'on',
            Off = 'off'
          }
          let s = Status.On
          s = 'TypeScript' // 不能將類型"TypeScript"分配給類型“Status”</pre>
          

          這里會報錯,因為字符串字面量類型'TypeScript'和Status.On是不兼容的。

          5、類類型的類型兼容性

          比較兩個類的類型兼容性時, 只有實例成員和方法會相比較,類的靜態成員和構造函數不進行比較 :

          <pre class="prettyprint hljs groovy" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">class Animal {
            static age: number;
            constructor(public name: string) {}
          }
          class People {
            static age: string;
            constructor(public name: string) {}
          }
          class Food {
            constructor(public name: number) {}
          }
          let a: Animal;
          let p: People;
          let f: Food;
          a = p; // ok
          a = f; // 不能將類型“Food”分配給類型“Animal”。</pre>
          

          Animal類和People類都有一個age靜態屬性,它們都定義了實例屬性name,類型是string。把類型為People的p賦值給類型為Animal的a是沒有問題的,因為類類型比較兼容性時,只比較實例的成員,這兩個變量雖然類型是不同的類類型,但是它們都有相同字段和類型的實例屬性name,而類的靜態成員是不影響兼容性的,所以它倆時兼容的。而類Food定義了一個實例屬性name,類型為number,所以類型為Food的f與類型為Animal的a類型是不兼容的,不能賦值。

          類的私有成員和受保護成員:

          類的私有成員和受保護成員會影響類的兼容性。當檢查類的實例兼容性時,如果目標(要被賦值的那個值)類型(這里實例類型就是創建它的類)包含一個私有成員,那么源(用來賦值的值)類型必須包含來自同一個類的這個私有成員,這就允許子類賦值給父類:

          <pre class="prettyprint hljs scala" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">class Parent {
            private age: number;
            constructor() {}
          }
          class Children extends Parent {
            constructor() {
              super();
            }
          }
          class Other {
            private age: number;
            constructor() {}
          }
          const children: Parent = new Children();
          const other: Parent = new Other(); // 不能將類型“Other”分配給類型“Parent”。類型具有私有屬性“age”的單獨聲明</pre>
          

          當指定 other 為 Parent 類類型,給 other 賦值 Other 創建的實例的時候,會報錯。因為 Parent 的 age 屬性是私有成員,外面是無法訪問到的,所以會類型不兼容。而children的類型我們指定為了Parent類類型,然后給它賦值為Children類的實例,沒有問題,是因為Children類繼承Parent類,且實例屬性沒有差異,Parent類有私有屬性age,但是因為Children類繼承了Parent類,所以可以賦值。

          同樣,使用 protected 受保護修飾符修飾的屬性,也是一樣的:

          <pre class="prettyprint hljs scala" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">class Parent {
            protected age: number;
            constructor() {}
          }
          class Children extends Parent {
            constructor() {
              super();
            }
          }
          class Other {
            protected age: number;
            constructor() {}
          }
          
          const children: Parent = new Children();
          const other: Parent = new Other(); // 不能將類型“Other”分配給類型“Parent”。屬性“age”受保護,但類型“Other”并不是從“Parent”派生的類</pre>
          

          6、泛型類型兼容性

          泛型中包含類型參數,這個類型參數可能是任何類型,使用時類型參數會被指定為特定的類型,而這個類型只影響使用了類型參數的部分:

          <pre class="prettyprint hljs typescript" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">interface Data<T> {}
          let data1: Data<number>;
          let data2: Data<string>;
          data1 = data2; // :white_check_mark:</pre>
          

          data1 和 data2 都是 Data 接口的實現,但是指定的泛型參數的類型不同,TS 是結構性類型系統,所以上面將 data2 賦值給 data1 是兼容的,因為 data2 指定了類型參數為 string 類型,但是接口里沒有用到參數 T,所以傳入 string 類型還是傳入 number 類型并沒有影響。

          再來看個例子:

          <pre class="prettyprint hljs powershell" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">interface Data<T> {
            data: T;
          }
          let data1: Data<number>;
          let data2: Data<string>;
          data1 = data2; // 不能將類型“Data<string>”分配給類型“Data<number>”。不能將類型“string”分配給類型“number”</pre>
          

          現在結果就不一樣了,賦值時報錯,因為 data1 和 data2 傳入的泛型參數類型不同,生成的結果結構是不兼容的。

          來源: https://www.51cto.com/article/716838.html


          主站蜘蛛池模板: 亚洲美女高清一区二区三区| AV无码精品一区二区三区宅噜噜| 色综合视频一区二区三区| 亚洲日韩国产一区二区三区在线| 国产精品亚洲一区二区麻豆| 痴汉中文字幕视频一区| 亚洲一区二区三区在线| 精品日韩在线视频一区二区三区 | 国产免费一区二区视频| 香蕉久久ac一区二区三区| 麻豆一区二区三区精品视频| 国产精品小黄鸭一区二区三区| 亚洲av综合av一区二区三区| 精品国产a∨无码一区二区三区| 红桃AV一区二区三区在线无码AV | 色一情一乱一伦一区二区三区日本| 精品一区二区三区在线播放视频 | 国产亚洲一区二区在线观看| 日韩精品一区二区三区在线观看 | 国产精品夜色一区二区三区| 国产亚洲综合一区柠檬导航| 中文字幕人妻无码一区二区三区| 无码AⅤ精品一区二区三区| 国产一区二区三区不卡在线观看| 国产精品资源一区二区| 爱爱帝国亚洲一区二区三区 | 国产精品熟女视频一区二区| 亚洲熟妇无码一区二区三区| 国产精品一区视频| 国产一区二区草草影院| 国产福利一区二区精品秒拍| 国产成人综合一区精品| 国产一区二区好的精华液 | 另类一区二区三区| 精品福利一区二区三区免费视频| 日韩一区二区三区视频| 亚洲日本乱码一区二区在线二产线| 亚洲一区二区三区日本久久九 | 亚洲bt加勒比一区二区| 亚洲一区无码精品色| 日韩精品一区二区午夜成人版|