解决input[type=number]无法显示非数字字符的问题

在移动端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 >

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值