简体   繁体   English

Android上的JavaScript中的触摸事件

[英]Touch events in JavaScript on Android

I have an HTML page with a div that acts like a momentary on-off switch. 我有一个带有div的HTML页面,它的作用类似于瞬时开关。 It works something like this: 它的工作原理如下:

     $('#btn').mousedown(function() {
         startAction()
     })
     $('#btn').mouseup(function() {
         stopAction()
     })
     $('#btn').mouseout(function() {
         stopAction()
     })

This works fine in a regular web browser. 在常规的网络浏览器中,这可以正常工作。 But it doesn't work when I load up the page in a WebView under Android. 但是,当我在Android下的WebView中加载页面时,它不起作用。 According to this, mousedown events don't work on Android like most people expect them to; 据此,鼠标按下事件在Android上不起作用,就像大多数人期望的那样; so, is there any other way to accomplish this? 那么,还有其他方法可以做到这一点吗? Basically, what I want is a notification when the user puts a finger down onto the widget, and when the finger is taken away. 基本上,我想要的是当用户将手指放到小部件上以及手指移开时发出的通知。

I'd prefer to use JQuery, but I don't have to. 我更喜欢使用JQuery,但不必这样做。 I'd also prefer a solution that works on other mobile platforms. 我也希望能在其他移动平台上使用的解决方案。

If I remember correctly, on Android, the webviews have JS disabled by default and need to be enabled. 如果我没记错的话,在Android上,默认情况下,Web视图已禁用JS并且需要将其启用。 You can enable them with the document at http://developer.android.com/resources/tutorials/views/hello-webview.html 您可以通过http://developer.android.com/resources/tutorials/views/hello-webview.html上的文档启用它们

I think really, you're up to the mercy of the device and the owner as to whether or not the user has javascript enabled. 我真的认为,您是否应该由设备和所有者来决定用户是否启用了JavaScript。

http://hubpages.com/hub/How-to-enable-disable-JavaScript-on-the-Droid-Android-phone http://hubpages.com/hub/How-to-enable-disable-JavaScript-on-the-Droid-Android-phone

Hope this helps ~Kevin 希望这会有所帮助〜Kevin

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

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