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

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

问题描述

我正在构建一个面向 Android 用户的移动网络应用.我需要知道我可以使用哪些 DOM 事件.我已经能够完成以下工作,但不是非常可靠:

  • 点击
  • 鼠标悬停
  • 鼠标按下
  • 鼠标
  • 改变

我无法使以下内容正常工作:

  • 按键
  • 按键
  • 按键

有谁知道支持的完整列表以及在什么情况下(例如,onchange 是否仅可用于表单输入?)?我在 Google 上找不到这方面的参考.

谢谢!

更新:我询问了Android 开发者列表中的相同问题.我将进行更多测试,并会在这里和那里发布我的结果.

解决方案

好的,这很有趣.我的用例是我在 WebKit 视图的屏幕上有一系列链接(A 标签).为了测试可用的事件区域,使用 jQuery 1.3.1,我附上了 这个页面(即使是那些没有意义的)链接然后在 Android 模拟器上使用向上、向下和输入控件,并指出哪些事件在哪些情况下被触发.>

这是我用来附加事件的代码,结果如下.请注意,我使用的是实时"事件绑定,因为对于我的应用程序,A 标记是动态插入的.

$.each(['模糊','改变','点击','上下文菜单','复制','切','dblclick','错误','重点','按键','按键','键盘','鼠标按下','鼠标移动','灭鼠','鼠标移到','鼠标','鼠标滚轮','粘贴','重启','调整大小','滚动','选择','提交',//W3C 事件'DOMActivate','DOMAttrModified','DOMCharacterDataModified','DOMFocusIn','DOMFocusOut','DOMMouseScroll','DOMNodeInserted','DOMNodeRemoved','DOMSubtreeModified','文本输入',//微软事件'启用','复制前','前切','前糊','停用','专注于','专注','散列','鼠标输入','鼠标离开'], 功能 () {$('a').live(this, function (evt) {警报(evt.type);});});

它是如何震动的:

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

  • 选择一个项目后,使用向下按钮移动到下一个项目,触发以下事件(按顺序):mouseoutmouseovermousemoveDOMFocusOutDOMFocusIn

  • 选择项目后,单击输入"按钮,以下事件(按顺序)触发:mousemovemousedownDOMFocusOut, mouseup, click, DOMActivate

这让我觉得是一堆随机垃圾.而且,谁是那个厚脸皮的仅限 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天全站免登陆