<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    J2EE社區

    茍有恒,何必三更起五更眠;
    最無益,只怕一日曝十日寒.
    posts - 241, comments - 318, trackbacks - 0, articles - 16

    DOM元素如何獲得焦點

    Posted on 2011-12-09 20:07 xcp 閱讀(2925) 評論(4)  編輯  收藏 所屬分類: Javascript
    首先讓我們看看哪些元素可以直接獲得焦點element..focus()

    // Form : http://www.w3.org/TR/html5/editing.html#focusable

    • a elements that have an href attribute
    • link elements that have an href attribute
    • button elements that are not disabled
    • input elements whose type attribute are not in the Hidden state and that are not disabled
    • select elements that are not disabled
    • textarea elements that are not disabled
    • command elements that do not have a disabled attribute
    • Elements with a draggable attribute set, if that would enable the user agent to allow the user to begin a drag operations for those elements without the use of a pointing device
    • Each shape that is generated for an area element

    而除上面以外的元素(比如:div,p)一般都無法直接獲得焦點,那如何處理呢?

    1. 給元素添加 contenteditable 屬性。

      // From : http://www.w3.org/TR/2009/WD-html5-20090423/editing.html#attr-contenteditable

      User agents must make editing hosts focusable (which typically means they enter the tab order).

    2. 給元素添加 tabindex 屬性。

      // From : http://www.w3.org/TR/2009/WD-html5-20090423/editing.html#attr-tabindex

      The tabindex content attribute specifies whether the element is focusable, whether it can be reached using sequential focus navigation, and the relative order of the element for the purposes of sequential focus navigation.

      非常推薦使用tabindex = -1 ,基本無副作用??!

      // From : http://www.w3.org/TR/2009/WD-html5-20090423/editing.html#attr-tabindex

      If the value is a negative integer: The user agent must allow the element to be focused, but should not allow the element to be reached using sequential focus navigation.

    綜述,使無法直接獲得焦點的元素獲得焦點的最佳實踐就是:給元素添加tabindex = -1




    名稱: ?4C.ESL | .↗Evon
    口號: 遇到新問題?先要尋找一個方案乄而不是創造一個方案こ
    mail: 聯系我


    Feedback

    # re: DOM元素如何獲得焦點  回復  更多評論   

    2011-12-10 07:06 by tbw淘寶商城
    遇到新問題?先要尋找一個方案乄而不是創造一個方案こ
    會的。。

    # re: DOM元素如何獲得焦點  回復  更多評論   

    2011-12-10 10:54 by tb
    給元素添加 tabindex 屬性

    # re: DOM元素如何獲得焦點  回復  更多評論   

    2011-12-10 13:02 by tb
    解釋的很好

    # re: DOM元素如何獲得焦點  回復  更多評論   

    2011-12-13 16:56 by tbw淘寶
    學習了
    主站蜘蛛池模板: 亚洲精品人成无码中文毛片| 成人免费一区二区三区在线观看| 亚洲av无码成人精品区一本二本| 日韩免费高清一级毛片| 一级毛片免费观看| 亚洲成AV人片在WWW色猫咪| 男人天堂免费视频| 在线观看特色大片免费视频| 亚洲国产理论片在线播放| 欧洲一级毛片免费| 久久亚洲精品国产亚洲老地址| 中文字幕视频免费在线观看| 亚洲精品国精品久久99热| 中文字幕不卡免费高清视频| 亚洲色精品aⅴ一区区三区 | 国产亚洲A∨片在线观看| 亚洲永久在线观看| 99久久国产精品免费一区二区| 亚洲av中文无码乱人伦在线播放| 亚洲另类无码专区首页| 国产高清免费观看| 亚洲成综合人影院在院播放| 91免费国产在线观看| 亚洲AV无码精品国产成人| 亚洲毛片网址在线观看中文字幕| WWW国产成人免费观看视频| 成人免费视频一区二区三区| 春暖花开亚洲性无区一区二区| 四虎精品视频在线永久免费观看| ww亚洲ww在线观看国产| 亚洲а∨天堂久久精品| 国偷自产一区二区免费视频| 亚洲国产成人久久99精品| 亚洲第一黄片大全| 99热在线免费观看| 日韩精品亚洲专区在线影视| 亚洲AV日韩精品久久久久久 | 国产av无码专区亚洲国产精品| 精品国产一区二区三区免费| 亚洲人妖女同在线播放| mm1313亚洲精品国产|