2012-03-08 8 views
1

그래서 여기에 절반의 양식이 있습니다.왜 .next() 메소드가 여기에서 작동하지 않습니까, jQuery?

나는 10 줄을 가지고 있는데, 나는 현재 줄에 뭔가가있을 때까지 다음 줄을 사용할 수 없기를 바란다.

Here is the Fiddle

JS :

$(document).ready(function(e){ 
    var openLines = $('.lineToText'); 
    if (openLines.length){ 
     //$('textarea').css('display', 'none'); 
     openLines.each(function(index, element){ 
      if (index>0) { 
       $(this).prop('disabled', true); 
       } 
      }); 
     $('.lineToText').on('keyup', this, function(){ 
      if (this.value.length){ 
       $(this).next('.lineToText').prop('disabled', false); //<== thought this would do the job but it's not 
       } else { 
        $(this).prop('disabled', true); 
        } 
      }); 
     } 
    }); 

HTML :

<TABLE SUMMARY="layout table" CELLPADDING="1" CELLSPACING="0" BORDER="0"> 

<TR> 

<TD VALIGN="TOP"><INPUT ID="Q1_96" ONCLICK="ExclusiveChoiceClick('Q1:96');" ONKEYPRESS="return true;" TABINDEX="100" TYPE="CHECKBOX" NAME="Q1:96" VALUE="96" ></TD><TD CLASS="CHOICES" VALIGN="TOP" >1: <INPUT class="lineToText" type="text" size="50"><br> 

2: <INPUT class="lineToText" type="text" size="50"><br> 

3: <INPUT class="lineToText" type="text" size="50"><br> 

4: <INPUT class="lineToText" type="text" size="50"><br> 

5: <INPUT class="lineToText" type="text" size="50"><br> 

6: <INPUT class="lineToText" type="text" size="50"><br> 

7: <INPUT class="lineToText" type="text" size="50"><br> 

8: <INPUT class="lineToText" type="text" size="50"><br> 

9: <INPUT class="lineToText" type="text" size="50"><br> 

10: <INPUT class="lineToText" type="text" size="50"><BR><TEXTAREA ID="Q1_96_O" TABINDEX="101" COLS="25" ROWS="5" CLASS="OPENENDEDANSWER" NAME="Q1:O"></TEXTAREA></TD> 

</TR> 

<TR> 

<TD VALIGN="TOP"><INPUT ID="Q1_99" ONCLICK="ExclusiveChoiceClick('Q1:99');" ONKEYPRESS="return true;" TABINDEX="102" TYPE="CHECKBOX" NAME="Q1:99" VALUE="99" ></TD><TD CLASS="CHOICES" VALIGN="TOP">Don't Know</TD> 

</TR> 

</TABLE> 

생각 $ (이) 다음 내용 ('. lineToText')가 다음 항목을 선택하는 것이 적절할 수 있지만 것 누가 내가 빠진 걸 말해 줄 수 있니? jQuery Docs에서

답변

3

:

설명 : 일치하는 요소의 집합에있는 각 요소의 바로 다음 형제를 가져옵니다. 선택기가 제공되면 해당 선택기와 일치하는 경우에만 다음 형제를 검색합니다.

대신 nextAll(".lineToText:first")을 사용하십시오.

바이올린 here

작동하지 않는 방식 때문에 당신의 <input /> 요소 사이에있는 <br /> 요소입니다 이유. 또한

+0

그게 영리한, 덕분에 나는 경우 아니, 숫자를 반환 this.value.length ... 즉시 나를 수로 일 위 –

0

,이 시도 :

if (this.value.length > 0) { 
    $(this).siblings('.lineToText').first().removeAttr('disabled'); 
} 
+0

대답을 받아 들일 겁니다이 0 (거짓)을 얻고 무언가가 있으면 양수 (참)를 얻습니다. –

관련 문제