简体   繁体   English

onkeypress 事件未在 Android Webview 4.4 中触发

[英]onkeypress event not firing in Android Webview 4.4

OnKeyPress is not being called in android webview... My Html code is simple OnKeyPress 没有在 android webview 中被调用......我的 Html 代码很简单

<input type="number" onkeypress="myFunc()"/>

function myFunc(){
alert(fired up!);
}

All the other keyevents ie keyup, keydown are working.所有其他按键事件,即 keyup、keydown 都在工作。

  • Try to use WebChromeClient for loading it.尝试使用 WebChromeClient 加载它。
  • Try to build with lower version.尝试使用较低版本构建。 Because in latest version API 17 and above they added JavascriptInterface .因为在最新版本的 API 17 及更高版本中,他们添加了JavascriptInterface You need to include this as a seperate class that extends JavascriptInterface.您需要将此作为扩展 JavascriptInterface 的单独类包含在内。

    To reduce application compatibility try to build with 16 or below.要降低应用程序兼容性,请尝试使用16或以下版本进行构建。

Android Webview really doesn't fire onkeypress event (even on newer versions of Android). Android Webview 确实不会触发onkeypress事件(即使在较新版本的 Android 上)。

One posible solution is to replace it with onkeyup or onkeydown , like this:一种可能的解决方案是将其替换为onkeyuponkeydown ,如下所示:

<input type="number" onkeyup="myFunc()"/>

function myFunc(){
   alert(fired up!);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM