我正在使用这个bootstrap-select的1.6.3来选择带有 Bootstrap 的菜单。
但是,当我通过我的表单进行选项卡时,它会跳过select具有类selectpicker的元素:即该元素不在选项卡顺序中。
GitHub 上有 1.6.4 版本,但我在 CDN 上找不到。
想知道是否有其他人遇到过这个问题以及是否有解决方法。
我正在使用这个bootstrap-select的1.6.3来选择带有 Bootstrap 的菜单。
但是,当我通过我的表单进行选项卡时,它会跳过select具有类selectpicker的元素:即该元素不在选项卡顺序中。
GitHub 上有 1.6.4 版本,但我在 CDN 上找不到。
想知道是否有其他人遇到过这个问题以及是否有解决方法。
Tab 顺序自然应该大致遵循 DOM 中 HTML 元素的顺序。
这是一个在版本 1.6.3 上运行良好的示例
<link href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.2/css/bootstrap.css" rel="stylesheet"/>
<link href="//cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.6.3/css/bootstrap-select.css" rel="stylesheet"/>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.2/js/bootstrap.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.6.3/js/bootstrap-select.js"></script>
<div class="form-group">
<label for="name">Name</label>
<input type="text" class="form-control" id="name">
</div>
<div class="form-group">
<label for="name">Something</label>
<select class="selectpicker form-control">
<option>Mustard</option>
<option>Ketchup</option>
<option>Relish</option>
</select>
</div>
<div class="form-group">
<label for="something">Something</label>
<input type="text" class="form-control" id="something">
</div>
如果您删除 bootstrap-select,并让常规<select>元素成为表单的一部分,它仍然有问题吗?如果是这样,引导选择不是问题的根源。
无论哪种方式,我们都可能需要一个工作演示来诊断问题。您可以在此答案中获取堆栈片段并开始添加它,直到您可以重新创建问题。
是的,有同样的问题,特别是在macbooks上,有一些偏好会跳过bootstrap select生成的按钮元素
$(document).ready(function () {
fixTabulation();
});
function fixTabulation() {
/* This can be used to auto-assign tab-indexes, or
# commented out if it manual tab-indexes have
# already been assigned.
*/
$('[tabindex]:not([tabindex="0"]):not([tabindex^="-"])').filter(":visible").each(function () {
$(this).attr('tabindex', Tab.i);
Tab.i++;
Tab.items++;
});
Tab.i = 0;
/* We need to listen for any forward or backward Tab
# key event tell the page where to focus next.
*/
$(document).on({
'keydown': function (e) {
if (navigator.appVersion.match("Safari")) {
if (e.keyCode == 9 && !e.shiftKey) { //Tab key pressed
e.preventDefault();
Tab.i != Tab.items ? Tab.i++ : Tab.i = 1;
if ($('[tabindex="' + Tab.i + '"]').prop('class').match('dropdown-toggle'))
$('[tabindex="' + Tab.i + '"]').click();
else
$('input[tabindex="' + Tab.i + '"], select[tabindex="' + Tab.i + '"], textarea[tabindex="' + Tab.i + '"]').not('input[type="hidden"]').focus();
}
if (e.shiftKey && e.keyCode == 9) { //Tab key pressed
e.preventDefault();
Tab.i != 1 ? Tab.i-- : Tab.i = Tab.items;
if ($('[tabindex="' + Tab.i + '"]').prop('class').match('dropdown-toggle'))
$('[tabindex="' + Tab.i + '"]').click();
else
$('input[tabindex="' + Tab.i + '"], select[tabindex="' + Tab.i + '"], textarea[tabindex="' + Tab.i + '"]').not('input[type="hidden"]').focus();
}
}
}
});
/* We need to update Tab.i if someone clicks into
# a different part of the form. This allows us
# to keep tabbing from the newly clicked input
*/
$('button[tabindex], input[tabindex], select[tabindex], textarea[tabindex]').not('input[type="hidden"]').focus(function (e) {
Tab.i = $(this).attr('tabindex');
console.log(Tab.i);
});
}
显然这是 Safari 的一个“功能”,它可以跳过下拉菜单。它是浏览器设置的一部分。看起来它也会影响 Firefox。
http://www.tonyspencer.com/2006/05/02/tab-skips-select-form-fields-in-mac-browsers/index.html