2012-01-23 2 views
0

$('#mapid').val($(".firstbox ul li:nth-child(" + mapi + ")").class()); 무기한 루프 정의되지 않은 오류를 반환하는 "정의"와 충돌 사이트는 ... jQuery를이 : n 번째 자식 선택기 던지는

이 난 일을 시도 : $('#mapid').val($(".firstbox ul li:nth-child(2)").class());과 같은 오류가 발생합니다.

요소는 틀림없이 존재하며, 스크립트는 페이지 하단에 위치합니다. 아니오, 저는 Wordpress를 사용하지 않습니다 (오류에 관한 공통된 주제 인 것을 알았습니다).

<div id="map-box" class="firstbox"> 
     <ul> 
         <li class="14" id="thelimit"> 
       <div class="left"> 
        <h1>The Limit</h1> 
        <span class="inf">A branching map. A mix-n match of alot of themes into one map.     <p>Recommended Players: 3<br /> 
        Author: <a href="http://www.minecraftforum.net/user/18586-timetoslide/" target="_new">timetoslide</a></p></span> 
       </div> 

       <div class="right" style="position: relative"> 
        <div style="width: 250px; height: 120; z-index: 6; position: absolute; top: 0px; height: 120px; left: 35px; cursor: pointer" class="righthover"></div> 
        <div style="background: url('maps/thelimit.jpg'); width:250px;height:150px;overfow:hidden;border:none;position: relative; z-index: 1"> 
        <div style="background: url('img/vignette.png') no-repeat center center; width: 100%; height: 100%; position: absolute; top: 0px; left: 0px; z-index: 2"></div> 
         <div class="seeList" style="width: 100%; height: 100%; background: url(img/cbg.png) repeat; color: white; font-family: Georgia, 'Times New Roman'; font-size: 24px; margin: 0; padding: 0; font-style: italic; text-align: center; z-index: 1; display: none;"><div style="padding: 20px; padding-top: 40px;">See full list of maps...</div></div> 
         <img src="img/border.png" style="z-index: 3" /> 
         <div class="directions" style="z-index: 5"></div> 
        </div> 
       </div> 
      </li> 
        <li class="13" id="lavaseaofsurvival"> 
       <div class="left"> 
        <h1>Lava Sea of Survival</h1> 
        <span class="inf">Try to survive by using only the resources provided. Did we mention you're floating above lava?     <p>Recommended Players: 4<br /> 
        Author: <a href="http://www.minecraftforum.net/user/1021295-meh-own/" target="_new">Meh_Own</a></p></span> 
       </div> 

       <div class="right" style="position: relative"> 
        <div style="width: 250px; height: 120; z-index: 6; position: absolute; top: 0px; height: 120px; left: 35px; cursor: pointer" class="righthover"></div> 
        <div style="background: url('maps/lavaseaofsurvival.jpg'); width:250px;height:150px;overfow:hidden;border:none;position: relative; z-index: 1"> 
        <div style="background: url('img/vignette.png') no-repeat center center; width: 100%; height: 100%; position: absolute; top: 0px; left: 0px; z-index: 2"></div> 
         <div class="seeList" style="width: 100%; height: 100%; background: url(img/cbg.png) repeat; color: white; font-family: Georgia, 'Times New Roman'; font-size: 24px; margin: 0; padding: 0; font-style: italic; text-align: center; z-index: 1; display: none;"><div style="padding: 20px; padding-top: 40px;">See full list of maps...</div></div> 
         <img src="img/border.png" style="z-index: 3" /> 
         <div class="directions" style="z-index: 5"></div> 
        </div> 
       </div> 
      </li> 
[etc...] 
+0

본 구체 예에서 더 리 없다 : n 번째 자식 (2). li : nth-child (0) 및 li : nth-child (1) – eiu165

+0

@ eiu165 "etc"는 더 있음을 의미합니다. –

답변

0

코드를 가진 클래스 = firstbox 여러 요소가 5 월, 그리고 그 중 일부는 액세스하려는 요소가 없을 수 있습니다 : 여기

는 HTML입니다.

귀하의 경우에는 문제를 해결할 수있는 ID 맵 박스가있는 요소의 하위 요소를 child() 함수로 참조 할 수 있습니다.

http://api.jquery.com/children/

+0

나는 그것이 나를 위해 일할 것이라고 생각하지 않는다. –

관련 문제