<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淘寶
    學習了
    主站蜘蛛池模板: 337p日本欧洲亚洲大胆人人| 国产成人精品日本亚洲18图| 9420免费高清在线视频| www免费黄色网| 国产日韩AV免费无码一区二区 | 久久精品视频免费看| 亚洲五月午夜免费在线视频| 国精产品一区一区三区免费视频| 永久在线观看www免费视频| 成年男女男精品免费视频网站| 中国xxxxx高清免费看视频| 成年私人影院免费视频网站| 亚洲一本大道无码av天堂| 亚洲国产老鸭窝一区二区三区 | 亚洲小视频在线观看| 亚洲砖码砖专无区2023| 一级一黄在线观看视频免费| 99re6在线精品视频免费播放 | 久久久久一级精品亚洲国产成人综合AV区| 亚洲国产精品第一区二区| 亚洲中文字幕久久精品蜜桃| 一区二区三区免费电影| 精品国产免费人成电影在线观看| yy6080亚洲一级理论| 亚洲精品一级无码鲁丝片 | 亚洲丁香色婷婷综合欲色啪| 亚洲精品GV天堂无码男同| a视频在线观看免费| 成年性羞羞视频免费观看无限| 国内精品久久久久久久亚洲| 亚洲一区二区影视| 中文字幕在线视频免费| 最近最好的中文字幕2019免费| 91麻豆精品国产自产在线观看亚洲| 2020久久精品亚洲热综合一本| 国产免费久久久久久无码| 好爽…又高潮了毛片免费看| 亚洲AV无码国产精品麻豆天美| 国产亚洲综合视频| 曰韩无码AV片免费播放不卡 | 日本视频在线观看永久免费|