【问题标题】:tab order for links in a simplemodal dialog简单模式对话框中链接的选项卡顺序
【发布时间】:2011-11-17 10:10:00
【问题描述】:

我正在使用出色的 jquery.simplemodal 对话框插件来显示项目列表。这些项目包含超链接。除了模式对话框中的链接没有作为选项卡顺序的一部分出现之外,这一切都很好。我已经尝试显式设置 tabindex,但由于某种原因,只有输入元素按 tab 顺序排列 - 如果我通过对话框进行 tab 键,我只是循环浏览 3 个输入元素而不点击锚点。

调用 simplemodal 插件是不是我做错了什么?

一个例子是http://dev.andrewbucknell.com/basic/demo1.html

演示的代码(带有相对路径)如下

<!DOCTYPE html>  
<html>  
<head>  
<title> SimpleModal Basic Modal Dialog </title>  
<meta name='author' content='Eric Martin' />  
<meta name='copyright' content='2010 - Eric Martin' /> 
<!-- Page styles -->  
<link type='text/css' href='css/demo.css' rel='stylesheet' media='screen' /> 
<!-- Contact Form CSS files -->  
<link type='text/css' href='css/basic.css' rel='stylesheet' media='screen' /> 
<!-- IE6 "fix" for the close png image -->  
<!--[if lt IE 7]>  
<link type='text/css' href='css/basic_ie.css' rel='stylesheet' media='screen' />  
<![endif]--> 
<!-- JS files are loaded at the bottom of the page -->  
</head>  
<body>  
<div id='container'>  
        <div id='logo'>  
                <h1>Simple<span>Modal</span></h1>  
                <span class='title'>A Modal Dialog Framework Plugin for jQuery</span>  
        </div>  
        <div id='content'>  
                <div id='basic-modal'>  
                        <h3>Basic Modal Dialog</h3>  
                        <p>A basic modal dialog with minimal styling and no additional options. There 
are a few CSS properties set internally by SimpleModal, however, SimpleModal relies mostly 
on style options and/or external CSS for the look and feel.</p>
                        <input type='button' name='basic' value='Demo' class='basic'/> or <a 
href='#' class='basic'>Demo</a>
                </div>  
                <div id="funddialog">  
                        <div id="fundpickfilter">  
                                <div class="fundfilter">  
                                        <label style="font-weight: bold;" for="filtertext">Find: </label>  
                                        <input class="tfilter" type="text" id="filtertext" value=""/>  
                                </div>  
                                <div id="fundactions">  
                                                <button type="button" id="fundsearch" 
class="searchbutton">Search</button>
                                                <button type="button" id="fundreset" 
class="resetbutton">Reset</button>  
                                </div>  
                        </div>  
                        <div id="fundpicklist">  
                                <div class="fund"><a href="http://www.slashdot.org" >Item 
1</a></div>  
                                <div class="fund"><a href="http://www.arstechnica.com" >Item 
2</a></div>  
                                <div class="fund"><a href="http://www.techmeme.com" >Item 
3</a></div>  
                        </div>  
                </div>  
                <!-- modal content -->  
                <div id="basic-modal-content">  
                        <div id="funddialog">  
                                <div id="fundpickfilter">  
                                        <div class="fundfilter">  
                                                <label style="font-weight: bold;" for="filtertext">Find: </label>  
                                                <input class="tfilter" type="text" id="filtertext" value=""/>  
                                        </div>  
                                        <div id="fundactions">  
                                                        <button type="button" id="fundsearch" 
class="searchbutton">Search</button>
                                                        <button type="button" id="fundreset" 
class="resetbutton">Reset</button>
                                        </div>  
                                </div>  
                                <div id="fundpicklist">  
                                        <div class="fund"><a href="http://www.slashdot.org" >Item 
1</a></div>  
                                        <div class="fund"><a href="http://www.arstechnica.com" >Item 
2</a></div>  
                                        <div class="fund"><a href="http://www.techmeme.com" >Item 
3</a></div>  
                                </div>  
                        </div>  
                </div>  
        </div>  
</div>  
<!-- Load jQuery, SimpleModal and Basic JS files -->  
<script type='text/javascript' src='js/jquery.js'></script>  
<script type='text/javascript' src='js/jquery.simplemodal.js'></script>  
<script type='text/javascript' src='js/basic.js'></script>  
</body>  
</html> 

【问题讨论】:

    标签: jquery dialog simplemodal


    【解决方案1】:

    我自己也遇到了这个问题。这是我到目前为止的工作。 Simplemodal 必须在“watchTab”和“focus”功能中添加选项卡导航,以便将焦点保持在模态中。它通过记录第一个和最后一个输入来实现这一点,当您通过它们时,专注于适当的其他输入。不幸的是,它只查看输入而不查看链接。这意味着您只能选择位于第一个和最后一个输入元素之间的链接。您可以覆盖或修改这些函数以获得所需的行为。像这样的:

    将第 473 行替换为 var input = $('#simplemodal-data :input:visible:enabled, #simplemodal-data a:visible')[p]();

    将第 592 行替换为 s.inputs = $('#simplemodal-data :input:visible:enabled, #simplemodal-data a:visible');

    这是一个简单的解决方案,如果浏览器不使用选项卡覆盖链接,它可能会中断。我会努力想出更好的。

    【讨论】:

    • 这是梦幻般的乔恩 - 感谢您的分享。我还将着眼于获得更强大的解决方案并将分享。感谢您为我指明正确的方向。
    • 快速跟进 - 我应用了您建议的更改,到目前为止它在 ie7 ie8 ie9 chrome 和 firefox 7 中运行良好。我将 #simplemodal-data 更改为 .simplemodal-data 以用于我的特定用例,到目前为止它看起来不错。再次感谢乔恩。
    【解决方案2】:

    我找到了 SimpleModal 1.4.2 的解决方案

    在线 609

    改变这个 s.inputs = $(':input:enabled:visible:first, :input:enabled:visible:last', s.d.data[0]);

    到这个 s.inputs = $('a:visible, :input:enabled:visible', s.d.data[0]).filter(':first,:last');

    【讨论】:

      【解决方案3】:

      s.d.data[0]s.d.data[0]还要注意,既不是现有的实现,也不是带有以下选择器:

      s.inputs = $(':input:enabled:visible:first, :input:enabled:visible:last', s.d.data[0]);
      

      也不是上面的答案,正确处理 tabindexes - 最后一个元素之后的切换将在 dom 中的第一个元素完成,而不是 tabindex 最少的那个(反之亦然) 要解决这个问题,你必须这样做:

      s.inputs = $.merge(self.smallestTabindex(s.d.data[0]), self.biggestTabindex(s.d.data[0]));
      

      其中最小/最大Tabindex 函数返回适当的元素

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-12-16
        • 1970-01-01
        • 1970-01-01
        • 2011-08-24
        相关资源
        最近更新 更多