当前位置:   article > 正文

H5 - input标签iOS原生键盘中文录入异常_ios中文输入框交互异常

ios中文输入框交互异常

查看:
https://blog.csdn.net/iotjin/article/details/112526267
最近在input搜索框中添加正则时发现,iOS原生键盘录入中文总是录入异常,安卓手机无异常,出现异常的写法:
html

<input id="inputId" type="search" class="mui-input-clear mui-indexed-list-search-input" placeholder="请输入"
maxlength="30"
onkeyup="value=value.replace(/[^\a-\z\A-\Z0-9\u4E00-\u9FA5\ ]/g,'')">
  • 1
  • 2
  • 3
1
  • 1

处理之后:

html

<input id="inputId" type="search" class="mui-input-clear mui-indexed-list-search-input" placeholder="请输入"
maxlength="30">
  • 1
  • 2
2
  • 1

js

//实时录入时通过正则剔除特殊字符(只能输入中文数字字母空格),此方式可解决iOS原生键盘中文录入异常
var flag = false;
$('#inputId').on({
    'compositionstart': function () {
        flag = true;
    },
    'compositionend': function () {
        flag = false;
        if (!flag) {
            document.getElementById("inputId").value = document.getElementById("inputId").value.replace(/[^\a-\z\A-\Z0-9\u4E00-\u9FA5\ ]/g, '');
        }
    },
    'input propertychange': function () {
        if (!flag) {
            document.getElementById("inputId").value = document.getElementById("inputId").value.replace(/[^\a-\z\A-\Z0-9\u4E00-\u9FA5\ ]/g, '');
        }
    }
});
 ```
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号