最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - backSpace not firing the keyup event in android mobile - Stack Overflow

programmeradmin4浏览0评论

This is the first time,I am working on mobile Apps.keyUp event not firing If I press backspace button.

I made a jsFiddle for reference.

Initially user entered 23 and then user deleted 3 using backspace button.While entering 23 event firing but while delete time event not firing.

I am using device : motorola motog,Android Version:4.4.2.

How can I fix this,can anyone help me with an example code.

This is the first time,I am working on mobile Apps.keyUp event not firing If I press backspace button.

I made a jsFiddle for reference.

Initially user entered 23 and then user deleted 3 using backspace button.While entering 23 event firing but while delete time event not firing.

I am using device : motorola motog,Android Version:4.4.2.

How can I fix this,can anyone help me with an example code.

Share Improve this question asked Mar 19, 2014 at 10:55 user3279058user3279058 5594 gold badges8 silver badges22 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 18

The problem is somewhere Chrome stopped firing keypress events for "backspace" since Android 4.4. This has been problematic in many webview based apps to catch required events. There is a small relief from this by using the input event that fires whenever user types something, pastes something, or taps on ".com" button in the keyboard, etc.

It is best to rely on input event if you are looking only to capture changes to the input. It is not useful if you want to do preventing default actions.

For your case, I think it should fit. But beware, of the support for this event for earlier than Android 4 version.

Updated fiddle - http://jsfiddle.net/aravindbaskaran/33Snz/24/

As solution, you could avoid using 'input' event, as mentioned @aravind. The problem is 'input' event does not work with <=ie9 and some mobile opera devices. Of course you could use browsers support detection, for example by modernizr or simple snippet and use supporting keyUp/input event.

On the other hand you could use all events together and browser will decide which one it will use, by itself. The problem is - in this case callback function will be calling twice at modern browsers which support both events.

Workaround is to use debounce function to prevent double calling.

$('.parent').on('change keydown input', _.debounce(function() {
    // whatever
}, 0));

Note that I'm using keydown event instead of keyup because I set delay only 0 milliseconds, so keyup will be call much later and _.debounce doesn't could help.

发布评论

评论列表(0)

  1. 暂无评论