在移動端webview實現的頁面中,有數字的地方必須使用input type="number"類型的input,否則觸發后的鍵盤為全鍵盤,而非數字鍵盤。但另外的一個問題是,input 為 type="number" 類型的無法顯示非數字字符,比如:12/23中/。
只能采取另外的思路來解決,比如:顯示的時候用非number類型的input或其它元素,當觸發onfocus后,利用js 動態修改為number類型。
<
input
class
="pg-page-num"
type
="text"
name
=""
value
="34/233"
id
="pageNum"
>
< input type ="hidden" name ="" value ="25" id ="totalPage" >
< script type ="text/javascript" >
var oPage = document.querySelector('#pageNum'),
oTotal = document.querySelector('#totalPage'),
sOldVal = '';
oPage.addEventListener('focus', function () {
this.type = 'number';
sOldVal = this.value;
}, false);
oPage.addEventListener('blur', function () {
var sVal = this.value;
this.type = 'text';
if (sVal != sOldVal) {
this.value += '/' + oTotal.value;
}
}, false);
</ script >
< input type ="hidden" name ="" value ="25" id ="totalPage" >
< script type ="text/javascript" >
var oPage = document.querySelector('#pageNum'),
oTotal = document.querySelector('#totalPage'),
sOldVal = '';
oPage.addEventListener('focus', function () {
this.type = 'number';
sOldVal = this.value;
}, false);
oPage.addEventListener('blur', function () {
var sVal = this.value;
this.type = 'text';
if (sVal != sOldVal) {
this.value += '/' + oTotal.value;
}
}, false);
</ script >