Android上的WebKit可以使用哪些DOM事件? [英] What DOM events are available to WebKit on Android?

查看:92
本文介绍了Android上的WebKit可以使用哪些DOM事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个面向Android用户的移动网络应用。我需要知道什么DOM事件可用于我。我已经能够做出以下工作,但不是非常可靠:




  • 点击

  • mouseover

  • mousedown

  • mouseup

  • 更改



我未能得到以下工作:




  • keypress

  • keydown

  • keyup



有谁知道什么是支持和在什么情况下(例如,是否只能用于形成输入?)?我在Google上找不到参考。



谢谢!



更新: 我在Android开发者列表中询问了相同的问题/ A>。我会做一些更多的测试,并会在这里和那里发布我的结果。

好的,这很有趣。我的用例是在WebKit视图的屏幕上有一系列链接( A 标签)。要测试什么事件区域可用,使用jQuery 1.3.1,我附加了每个事件列在这个页面(甚至没有意义)的链接,然后使用上,下,并在Android模拟器上输入控件,并指出哪些事件触发了哪些情况。 p>

这是我用来附加事件的代码,结果如下。注意,我使用live事件绑定,因为对于我的应用程序,动态插入 A 标签。

  $。each([
'blur',
'change',
'click',
'contextmenu',
'copy',
'cut',
'dblclick',
'error',
'focus',
'keydown',
' keypress',
'keyup',
'mousedown',
'mousemove',
'mouseout',
'mouseover',
' ,
'mousewheel',
'paste',
'reset',
'resize',
'scroll',
'select',
'submit',

// W3C事件
'DOMActivate',
'DOMAttrModified',
'DOMCharacterDataModified',
'DOMFocusIn' ,
'DOMFocusOut',
'DOMMouseScroll',
'DOMNodeInserted',
'DOMNodeRemoved',
'DOMSubtreeModified',
'textInput',

// Microsoft事件
'activate',
'beforecopy',
'beforecut',
'beforepaste',
'deactivate',
'focusin',
'focusout',
'hashchange',
'mouseenter',
'mouseleave'
],function(){
$('a')。live(this,function(evt)){
alert(evt.type);
});
});

以下是如何摆脱:




  • 在第一页上加载没有突出显示(任何项目周围没有丑陋的橙色选择框),使用向下按钮选择第一个项目,以下事件触发(按顺序): mouseover mouseenter mousemove DOMFocusIn


  • 选择一个项目,使用向下按钮移动到下一个项目,触发以下事件(按顺序): mouseout mouseover mousemove DOMFocusOut DOMFocusIn


  • 选中一个项目,点击输入按钮,以下事件触发(按顺序): mousemove mousedown DOMFocusOut mouseup 点击 DOMActivate / p>




这是一堆随机垃圾。而且,那个那个厚脸皮的只有IE的事件( mouseenter )做了一个冒险,然后休息一天?哦,至少现在我知道要观看哪些事件。



如果别人想要采取我的测试代码并做更彻底的运行,那可能会很好使用表单元素,图像等。


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:

  • 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.

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.

解决方案

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.

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.

$.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

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.

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.

这篇关于Android上的WebKit可以使用哪些DOM事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆