移动端、手机网站中文输入法下keyup事件部分按键无效
2016-03-10 11:42
519 查看
文章来源: http://www.itnose.net/detail/6132370.html
微信公众平台开发时,客户提需求“输入框中输入内容时,输入框后边显示清除按钮,清除输入框中的内容”,使用“keyup”事件时在中文输入法下部分按键keyup事件无效, 以下为解决方案。
绑定“input”和“propertychange”事件可以解决,以下为代码:
另外网上还有另一种解决方案,具体思路为给输入框注册focus事件,隔段时间去检索下,我个人还是比较倾向于上面那种方法的,以下为第二种方案代码:
微信公众平台开发时,客户提需求“输入框中输入内容时,输入框后边显示清除按钮,清除输入框中的内容”,使用“keyup”事件时在中文输入法下部分按键keyup事件无效, 以下为解决方案。
绑定“input”和“propertychange”事件可以解决,以下为代码:
var bind_name="input";//定义所要绑定的事件名称 if(navigator.userAgent.indexOf("MSIE")!=-1) bind_name="propertychange";//判断是否为IE内核 IE内核的事件名称要改为propertychange /*输入框键盘离开事件绑定*/ $("input").bind(bind_name,function(){ if(this.value!=null&&this.value!=""){ var inputWidth=$(this).outerWidth(); var inputHeight=$(this).outerHeight(); var inputOffset = $(this).offset(); var inputTop=inputOffset.top; var inputLeft=inputOffset.left; $("#clearDiv").css({top:inputTop+2,left:inputLeft+inputWidth-27}).show(); inputObj=this }else{ $("#clearDiv").hide(); } });
另外网上还有另一种解决方案,具体思路为给输入框注册focus事件,隔段时间去检索下,我个人还是比较倾向于上面那种方法的,以下为第二种方案代码:
<script language="javascript" type="text/javascript" src="jquery.js"></script> <script> $(function () { $('#wd').bind('focus',filter_time); }) var str = ''; var now = '' filter_time = function(){ var time = setInterval(filter_staff_from_exist, 100); $(this).bind('blur',function(){ clearInterval(time); }); }; filter_staff_from_exist = function(){ now = $.trim($('#wd').val()); if (now != '' && now != str) { console.log(now); } str = now; } </script>
相关文章推荐
- android基础开发之scrollview
- Android ViewGroup事件分发机制
- android提交GIT .gitignore过滤文件配置信息
- Android类库打包方法探究
- [Ljava.lang.Object; cannot be cast to [Ljava.lang.String;
- 解决ios下的微信打开的页面背景音乐无法自动播放
- iOS-关于@property和@synthesize
- 雅思听听app
- Xcode 如何修改APP的名称
- ios开发--多台电脑共用一个开发证书的方法
- Android设备连接Unity Profiler性能分析器
- cocos2d-x 3.10 安卓 屏幕适配
- Android系统设置— android.provider.Settings
- 设计模式_单例模式
- iOS Client 与WebSocket 通信(一)
- Android中实时视频传输(摄像头实时视频传输)解决方案<二>
- ios html5 网页取消默认样式
- cocos2d-x之猜数字游戏
- ios 常用第三方类库
- android 中 dumpsys 命令使用