2013-07-25 2 views
2

일부 필드를 숨길 수있는 양식이 있습니다. 적절한 접근성을 위해 tabindex를 jQuery와 함께 추가합니다. 현재 보이는 요소에만 적용됩니다.동적 요소에 tabindex 추가

위대한 작품입니다. 그러나 특정 클래스 이름이있는 범위에 tabindex를 추가하기로 결정한 경우 해당 요소는 건너 뜁니다. 왜?

$(':input:visible, .tabIn').each(function (i) { 
    $(this).attr('tabindex', i + 1); 
}); 

<span class="tabIn">my span</span> 
+0

에 스킵 된? 그것은 tabindex를 전혀 가져 오지 않습니까? – putvande

+0

HTML5에서 모든 태그는 tabindex를 가질 수 있습니다. – putvande

+0

예, tabindex가 추가되지 않았습니다. 그러나 수동으로 추가하면 탭이 잘 작동합니다. 내 jQuery 함수에 구문 오류가 있습니까? ... 말이 안된다. – santa

답변

0

이 나를 위해 올바른 작동 :

<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> 
관련 문제