1. 程式人生 > >總結一下這些天遇到的面試題

總結一下這些天遇到的面試題

1,假如 有個陣列 var arr=[1,2,5,6,3,1] 如何刪除陣列元素為2的數字

 

var arr = [1,2,5,6,3,1];
思路: 遍歷找到元素為2 的下標,移除它
 for(let i=0;i<arr.length;i++){
    if(arr[i] == 2){
       arr.splice(i,1);
   }
}

記成java中的remove()了,,,,,

2,怎麼獲取當前瀏覽器的src

window.location.href

 記錄一下其他的(萬一以後問到)

設定或獲取物件指定的檔名或路徑。
alert(window.location.pathname)
設定或獲取整個 URL 為字串。
alert(window.location.href);
設定或獲取與 URL 關聯的埠號碼。
alert(window.location.port)
設定或獲取 URL 的協議部分。
alert(window.location.protocol)
設定或獲取 href 屬性中在井號“#”後面的分段。
alert(window.location.hash)
設定或獲取 location 或 URL 的 hostname 和 port 號碼。
alert(window.location.host)
設定或獲取 href 屬性中跟在問號後面的部分。
alert(window.location.search)

  3,mysql 是關係型資料庫嗎

   弱弱的回答 是

4,css的偽類有哪些

       anchor偽類

    

a:link {color:#FF0000;} /* 未訪問的連結 */
a:visited {color:#00FF00;} /* 已訪問的連結 */
a:hover {color:#FF00FF;} /* 滑鼠劃過連結 */
a:active {color:#0000FF;} /* 已選中的連結 */

 

選擇器 示例 示例說明
:checked input:checked 選擇所有選中的表單元素
:disabled input:disabled 選擇所有禁用的表單元素
:empty p:empty 選擇所有沒有子元素的p元素
:enabled input:enabled 選擇所有啟用的表單元素
:first-of-type p:first-of-type 選擇每個父元素是p元素的第一個p子元素
:in-range input:in-range 選擇元素指定範圍內的值
:invalid input:invalid 選擇所有無效的元素
:last-child p:last-child 選擇所有p元素的最後一個子元素
:last-of-type p:last-of-type 選擇每個p元素是其母元素的最後一個p元素
:not(selector) :not(p) 選擇所有p以外的元素
:nth-child(n) p:nth-child(2) 選擇所有 p 元素的父元素的第二個子元素
:nth-last-child(n) p:nth-last-child(2) 選擇所有p元素倒數的第二個子元素
:nth-last-of-type(n) p:nth-last-of-type(2) 選擇所有p元素倒數的第二個為p的子元素
:nth-of-type(n) p:nth-of-type(2) 選擇所有p元素第二個為p的子元素
:only-of-type p:only-of-type 選擇所有僅有一個子元素為p的元素
:only-child p:only-child 選擇所有僅有一個子元素的p元素
:optional input:optional 選擇沒有"required"的元素屬性
:out-of-range input:out-of-range 選擇指定範圍以外的值的元素屬性
:read-only input:read-only 選擇只讀屬性的元素屬性
:read-write input:read-write 選擇沒有隻讀屬性的元素屬性
:required input:required 選擇有"required"屬性指定的元素屬性
:root root 選擇文件的根元素
:target #news:target 選擇當前活動#news元素(點選URL包含錨的名字)
:valid input:valid 選擇所有有效值的屬性
:link a:link 選擇所有未訪問連結
:visited a:visited 選擇所有訪問過的連結
:active a:active 選擇正在活動連結
:hover a:hover 把滑鼠放在連結上的狀態
:focus input:focus 選擇元素輸入後具有焦點
:first-letter p:first-letter 選擇每個<p> 元素的第一個字母
:first-line p:first-line 選擇每個<p> 元素的第一行
:first-child p:first-child 選擇器匹配屬於任意元素的第一個子元素的 <p> 元素
:before p:before 在每個<p>元素之前插入內容
:after p:after 在每個<p>元素之後插入內容
:lang(language) p:lang(it) 為<p>元素的lang屬性選擇一個開始值

 

5,怎麼用css 實現隔行變色(這下記住了 :nth-child())

  

          <ul class="my_ul">
		  <li>1</li>
		  <li>2</li>
		  <li>3</li>
		  <li>4</li>
		  <li>4</li>
        </ul>
  .my_ul>li:nth-child(2n){
		    	background-color: #800080;
   }

6,vue的生命週期函式

beforeCreate
created
beforeMount
mounted
beforeUpdate
updated
beforeDestroy
destroyed

7,小程式的生命週期函式

 

1 監聽頁面載入

onLoad: function (options) {}, 

一個頁面只會呼叫一次,可以在 onLoad 中獲取開啟當前頁面所呼叫的 query 引數。 

2 監聽頁面初次渲染完成

onReady: function () {}, 

一個頁面只會呼叫一次,代表頁面已經準備妥當,可以和檢視層進行互動。 

3 監聽頁面顯示 

onShow: function () {}, 

每次開啟頁面都會呼叫一次。 

3 監聽頁面隱藏

onHide: function () {}, 

當navigateTo或底部tab切換時呼叫。 

4 監聽頁面解除安裝

onUnload: function () {}, 

當redirectTo或navigateBack的時候呼叫。 

微信小程式的 app.js 中 獨有的 函式

5 監聽小程式初始化

onLaunch:function () {}, 

當小程式初始化完成時,會觸發 onLaunch(全域性只觸發一次) 

6錯誤監聽函式

onError:function () {},