Android 上的 WebKit 可以使用哪些 DOM 事件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/475674/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What DOM events are available to WebKit on Android?
提问by Andrew Hedges
I'm building a mobile web app targeting Android users. I need to know what DOM events are available to me. I have been able to make the following work, but not terribly reliably:
我正在构建一个针对 Android 用户的移动网络应用程序。我需要知道我可以使用哪些 DOM 事件。我已经能够完成以下工作,但不是非常可靠:
- click
- mouseover
- mousedown
- mouseup
- change
- 点击
- 鼠标移到
- 鼠标按下
- 鼠标向上
- 改变
I have not been able to get the following to work:
我无法使以下内容起作用:
- keypress
- keydown
- keyup
- 按键
- 按键
- 按键
Does anyone know the full list of what is supported and in what contexts (e.g., is onchange only available to form inputs?)? I can't find a reference for this on The Googles.
有谁知道支持的内容以及在什么情况下的完整列表(例如,onchange 是否仅可用于表单输入?)?我在 Google 上找不到这方面的参考。
Thanks!
谢谢!
Update:I asked the same question on the Android developers list. I will be doing some more testing and will post my results both here and there.
更新:我在 Android 开发人员列表上问了同样的问题。我将进行更多测试,并会在这里和那里发布我的结果。
采纳答案by Andrew Hedges
OK, this is interesting. My use case is that I have a series of links (A
tags) on a screen in a WebKit view. To test what events area available, using jQuery 1.3.1, I attached every event listed on this page(even ones that don't make sense) to the links then used the up, down, and enter controls on the Android emulator and noted which events fired in which circumstances.
好吧,这很有趣。我的用例是我A
在 WebKit 视图的屏幕上有一系列链接(标签)。为了测试可用的事件区域,使用 jQuery 1.3.1,我将此页面上列出的每个事件(即使是没有意义的事件)附加到链接,然后在 Android 模拟器上使用向上、向下和输入控件并注明哪些事件在哪些情况下触发。
Here is the code I used to attach the events, with results to follow. Note, I'm using "live" event binding because for my application, the A
tags are inserted dynamically.
这是我用来附加事件的代码,结果如下。请注意,我使用的是“实时”事件绑定,因为对于我的应用程序,A
标签是动态插入的。
$.each([
'blur',
'change',
'click',
'contextmenu',
'copy',
'cut',
'dblclick',
'error',
'focus',
'keydown',
'keypress',
'keyup',
'mousedown',
'mousemove',
'mouseout',
'mouseover',
'mouseup',
'mousewheel',
'paste',
'reset',
'resize',
'scroll',
'select',
'submit',
// W3C events
'DOMActivate',
'DOMAttrModified',
'DOMCharacterDataModified',
'DOMFocusIn',
'DOMFocusOut',
'DOMMouseScroll',
'DOMNodeInserted',
'DOMNodeRemoved',
'DOMSubtreeModified',
'textInput',
// Microsoft events
'activate',
'beforecopy',
'beforecut',
'beforepaste',
'deactivate',
'focusin',
'focusout',
'hashchange',
'mouseenter',
'mouseleave'
], function () {
$('a').live(this, function (evt) {
alert(evt.type);
});
});
Here's how it shook out:
这是它的震动方式:
On first page load with nothing highlighted (no ugly orange selection box around any item), using down button to select the first item, the following events fired (in order):
mouseover
,mouseenter
,mousemove
,DOMFocusIn
With an item selected, moving to the next item using the down button, the following events fired (in order):
mouseout
,mouseover
,mousemove
,DOMFocusOut
,DOMFocusIn
With an item selected, clicking the "enter" button, the following events fired (in order):
mousemove
,mousedown
,DOMFocusOut
,mouseup
,click
,DOMActivate
在第一页加载时没有突出显示(任何项目周围都没有丑陋的橙色选择框),使用向下按钮选择第一个项目,触发以下事件(按顺序):
mouseover
,mouseenter
,mousemove
,DOMFocusIn
选择一个项目后,使用向下按钮移动到下一个项目,将触发以下事件(按顺序):
mouseout
,mouseover
,mousemove
,DOMFocusOut
,DOMFocusIn
选择一个项目后,单击“输入”按钮,将触发以下事件(按顺序):
mousemove
,mousedown
,DOMFocusOut
,mouseup
,click
,DOMActivate
This strikes me as a bunch of random garbage. And, who's that cheeky IE-only event (mouseenter
) making a cameo, then taking the rest of the day off? Oh well, at least now I know what events to watch for.
这让我觉得是一堆随机垃圾。而且,谁是那个厚脸皮的 IE 专用活动 ( mouseenter
) 客串演出,然后休息一天?哦,好吧,至少现在我知道要关注哪些事件了。
It would be great if others want to take my test code and do a more thorough run through, perhaps using form elements, images, etc.
如果其他人想要使用我的测试代码并进行更彻底的运行,可能会使用表单元素、图像等,那就太好了。
回答by Oskar Austegard
Since this is the second most popular Android + JavaScript post on SO (which is just a sad commentary on the state of web development targeting the Android platform), I thought it may be worthwhile including a link to pkk's touch event test results at http://www.quirksmode.org/mobile/tableTouch.htmland also http://www.quirksmode.org/mobile/in general.
由于这是 SO 上第二受欢迎的 Android + JavaScript 帖子(这只是对针对 Android 平台的 Web 开发状态的悲伤评论),我认为可能值得在http: 中包含指向 pkk 触摸事件测试结果的链接 : //www.quirksmode.org/mobile/tableTouch.html以及http://www.quirksmode.org/mobile/。
回答by Roman Nurik
As of Android 1.5, the same touch(start|move|end|cancel) events that the iPhone supports work in Android as well.
从 Android 1.5 开始,iPhone 支持的相同 touch(start|move|end|cancel) 事件也适用于 Android。
One problem I found was that touchmove ends get queued up. No workaround yet.
我发现的一个问题是 touchmove 结束排队。还没有解决方法。