<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 閱讀(2926) 評論(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在线播放| 青青久久精品国产免费看| 四虎影永久在线高清免费| 男女超爽视频免费播放| 国产hs免费高清在线观看| 免费播放国产性色生活片| 亚洲一区二区视频在线观看| 国产精品综合专区中文字幕免费播放| 无码专区一va亚洲v专区在线| 日韩一区二区三区免费播放| 国产亚洲婷婷香蕉久久精品| 香蕉免费一区二区三区| 亚洲第一页在线观看| 最新中文字幕免费视频| 日韩国产精品亚洲а∨天堂免| 亚洲国产综合久久天堂| 十八禁视频在线观看免费无码无遮挡骂过| 亚洲AV中文无码乱人伦下载| 亚洲最大免费视频网| MM1313亚洲精品无码久久| 中文亚洲成a人片在线观看| 久久成人免费播放网站| 亚洲av永久无码嘿嘿嘿| 国产国产人免费人成免费视频| 精品一区二区三区免费视频| 久久精品国产亚洲AV香蕉| 免费人成在线视频| 七次郎成人免费线路视频| 亚洲国产成人久久精品动漫| 一个人看的www在线观看免费| 色天使亚洲综合一区二区| 亚洲情综合五月天| 在线观看免费人成视频色9| 免费中文字幕视频| 亚洲成年人电影网站| 亚洲国产精品成人| 国产精品视频免费观看| 一级女人18片毛片免费视频| 亚洲视频一区在线播放|