App下載

前端開發(fā)input常見問題有哪些?問題總結!

猿友 2021-08-04 11:54:20 瀏覽數 (1891)
反饋

今天小編和大家分享個有關于開發(fā)基礎標簽的內容吧!那么下面我們來討論有關于:“前端開發(fā)input常見問題有哪些?”這個問題的相關內容吧!

1. 去掉input 在iOS中的默認圓角和內陰影

iOS下 input會有自帶的圓角和內陰影,去掉方法如下:

input{
    -webkit-appearance: none;
    border-radius: 0;
}

2. 焦點在 input 時,placeholder 沒有隱藏

input:focus::-webkit-input-placeholder{
    opacity: 0;
}

3. input 輸入框調出數字鍵盤

單獨使用type="number"時,iOS調起的并不是九宮格樣式的數字鍵盤,如果需要調起九宮格的數字鍵盤需要加上 pattern="[0-9]*" 屬性:

<!-- 數字鍵盤 帶有符號,非九宮格樣式 -->
<input type="number"/>

<!-- 九宮格數字鍵盤 -->
<input type="number" pattern="[0-9]*"/>

<!-- 電話號碼鍵盤 -->
<input type="tel"/>

4. 搜索時,鍵盤的回車按鈕文字設定為“搜索”

解決: input 使用 type="search",放在 form 表單內。兩者結合就能使輸入法中的回車按鈕文字變?yōu)椤八阉鳌?/p>

<form action="">
    <input type="search" />
</form>

5. 改變input placeholder顏色

::-webkit-input-placeholder { /* WebKit browsers */
  color:    #999;
}
:-moz-placeholder { /* Mozilla Firefox 4 to 18 */
  color:    #999;
  opacity:  1;
}
::-moz-placeholder { /* Mozilla Firefox 19+ */
  color:    #999;
  opacity:  1;
}
:-ms-input-placeholder { /* Internet Explorer 10+ */
  color:    #999;
}

input::-webkit-input-placeholder, textarea::-webkit-input-placeholder { /* WebKit*/  
    color:    #666;  
}  
input:-moz-placeholder, textarea:-moz-placeholder { /* Mozilla Firefox 4 to 18 */  
    color:    #666;  
}  
input::-moz-placeholder, textarea::-moz-placeholder { /* Mozilla Firefox 19+ */  
    color:    #666;  
}  
input:-ms-input-placeholder, textarea:-ms-input-placeholder { /* IE 10+ */  
    color:    #666;  
} 

6. iOS下autofocus focus()失效的問題

iOS下不能自動獲取焦點,必須是在監(jiān)聽到用戶發(fā)出的事件的函數中執(zhí)行focus才有用,比如:

// openNotifyReplay 是click觸發(fā)的事件
openNotifyReplay = (e) => {
    this.setState({
        notifyReplayVisible: true
    }, ()=>{
        document.getElementById("replayPopupText").focus()
    })
}

到此這篇關于“前端開發(fā)input常見問題有哪些?”的文章就介紹到這了,更多有關于HTML5的內容大家可以搜索W3Cschool進行學習! 

0 人點贊