代码之家  ›  专栏  ›  技术社区  ›  avernet

如何防止带有overflow-y:scroll的框窃取Firefox上的焦点选项卡?

  •  2
  • avernet  · 技术社区  · 15 年前

    请考虑具有以下代码的页面:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
            "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
            <style type="text/css">
                .steal-focus { overflow-y: scroll }
            </style>
        </head>
        <body>
            <form action="/">
                <input type="text" value="First">
                <div class="steal-focus">Content</div>
                <input type="text" value="Second">
            </form>
        </body>
    </html>
    
    1. 第二次点击标签:焦点转到 <div> 而不是第二个文本字段,因为 overflow-y: scroll .

    这种行为是Firefox独有的:在IE、Safari或Chrome上都不会发生。我怎么才能避免这种行为,这听起来像一个Firefox的错误呢?我想把帐单跳过 <部门> 即使它有一个 overflow-y:滚动

    1 回复  |  直到 15 年前
        1
  •  2
  •   Matt Ball    15 年前

    使用 the tabIndex attribute 标签 跳过去。这样地:

    <body>
        <form action="/">
            <input type="text" value="First" tabIndex="1">
            <div class="steal-focus">Content</div>
            <input type="text" value="Second" tabIndex="2">
        </form>
    </body>
    
    推荐文章