2014-01-26 62 views
0

我下<td>標籤2周的div:查找最接近/下一格

// first 
<td> 
    <div class="date">$row[11]</div> 
</td> 
<td class="status1"> 
    <div class="question"> 
     <form action="update.php" method="post" id="form-id" enctype="multipart/form-data"> 
     <div class="recstatus">$row[12]</div> 
     <input type="hidden" value="$row[12]" name="recstatus"> 
     <input type="hidden" value=$row[1] name="audit_name"> 
     <select name="status" class="select" > 
     <option value="1">1</option> 
     <option value="2">2</option> 
     <option value="3">3</option> 
     <option selected="selected">choose</option> 
     </select> 


     <div class="subquestion"> 
     <label>upload file</label> 
     <input type="file" name="file"> 
     <input type="submit" name="submit"> 
     </div> 

    </form><br/> 
    </div> 

    //second 
    <div class="question1"> 
     <form action="update.php" method="post" id="form-id" enctype="multipart/form-data"> 
      <input type="hidden" value=$row[1] name="audit_name"> 
     <select name="status1" > 
      <option value="4">4</option> 
      <option selected="selected">choose</option> 
     </select> 
     <div class="subquestion1"> 
      <label>upload file</label> 
      <input type="file" name="file"> 
      <input type="submit" name="submit"> 
     </div> 
     </form> 

    </div> 
</td> 

這裏去JQuery的:

$(document).ready(function() { 
    $('.date').each(function() { 
     $('.question1').hide(); 
     var date = new Date($(this).text().replace("-", "/")); 
     var recstatus = $(this).closest('td').next().find('.recstatus'); 
     if (new Date() > date && recstatus.text() == 3) { 
      recstatus.addClass('invaliddate'); 
      //if this is true then hide first div and show second div 
      // something like this.. but this isn't working 
      // i need closest/next div (this divs are in cycle) 
      $(this).closest("div").find(".question1").show(); 
      $(this).closest("div").find(".question").hide(); 
     } 
    }); 
}); 

我想說明問題1格,如果(這個jQuery if語句是真實的)和隱藏問題div 但他們在週期內<td>所以我想要使用下一個/最接近的功能

+3

「.date」元素在哪裏? – Satpal

+0

這裏是..代碼頂部 – Gtopuria

回答

2

你需要找到父母td el然後下一個兄弟td你需要找到有問題的div

$(this).closest("td").next().find(".question1").show(); 
$(this).closest("td").next().find(".question").hide(); 
+0

謝謝你的幫助。 – Gtopuria

+1

@HadesNebula,你已經知道了答案var recstatus = $(this).closest('td')。next()。find('。recstatus');' – Satpal

+0

@Satpal我錯過了! –