将tabindex添加到动态元素
我有一个表单,其中一些可能被隐藏。为了正确无障碍我添加的tabIndex使用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> 
以上是 将tabindex添加到动态元素 的全部内容, 来源链接: utcz.com/qa/259081.html





