我有一个带有字段的表单,其中一些字段可能是隐藏的。为了获得适当的可访问性,我使用jQuery添加了tabindex,只添加到当前可见的元素:
$(':input:visible').each(function (i) {
$(this).attr('tabindex', i + 1);
});
它非常有效。然而,当我决定向具有特定类名的跨度添加tabindex时,该元素被跳过了。为什么?
$(':input:visible, .tabIn').each(function (i) {
$(this).attr('tabindex', i + 1);
});
<span class="tabIn">my span</span>
这对我来说是正确的:
<html>
<head>
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$(':input:visible, .tabIn').each(function (i) {
$(this).css('background-color','red').attr('tabindex', i + 1);
});
});
</script>
</head>
<body>
<span class="tabIn">my span</span>
<input name="tabIn" />
</body>
</html>