简体   繁体   English

找到最近/下一个div

[英]Find closest/next div

I have 2 divs under <td> tag : 我在<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>

Here goes JQuery : 这里是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();
        }
    });
});

I want to show question1 div if (this jquery if statement is true) and hide question div but they are under <td> in cycle so i want next/closest functions to use 我想显示question1 div if(这个jquery if语句是真的)并隐藏问题div但它们在循环中的<td>下所以我想要使用next / nearest函数

You need find the parent td element then the next sibling td where you need to find the div's in question 你需要找到父td元素,然后找到你需要找到有问题的div的下一个兄弟td

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM