문제

Android 사용자를 대상으로하는 모바일 웹 앱을 구축하고 있습니다. 나에게 어떤 DOM 이벤트를 사용할 수 있는지 알아야합니다. 나는 다음과 같은 일을 할 수 있었지만 정말 확실하게는 안됩니다.

  • 딸깍 하는 소리
  • 마우스 오버
  • 마우스 own
  • 마우스 업
  • 변화

나는 다음과 같은 일을 할 수 없었습니다.

  • 키 누름
  • 키 다운
  • 키 업

누구든지 지원되는 내용의 전체 목록과 어떤 맥락에서 (예 : onchange가 입력을 형성 할 수 있습니까?)를 알고 있습니까? 구글에서 이것에 대한 참조를 찾을 수 없습니다.

감사!

업데이트: 나는 물었다 Android 개발자 목록에 동일한 질문이 있습니다. 나는 더 많은 테스트를 할 것이며 여기저기서 결과를 게시 할 것입니다.

도움이 되었습니까?

해결책

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.

다른 팁

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.html and also http://www.quirksmode.org/mobile/ in general.

As of Android 1.5, the same touch(start|move|end|cancel) events that the iPhone supports work in Android as well.

One problem I found was that touchmove ends get queued up. No workaround yet.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top