2017-10-16 54 views
0

复选框被选中时,我想隐藏.panel。但它没有隐瞒:如何隐藏与特定类别最近的元素?

$(".done").on("change", function() { 
 
    if ($(this).is(":checked")) { 
 
    $(this).closest(".panel").hide; 
 
    } 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 

 
<li class="panel" style="background:#f4f4f4;"> 
 
    <table style="width:100%"> 
 
     <tbody> 
 
      <tr> 
 
       <td style="width:45px"> 
 
        <span class="handle ui-sortable-handle"> 
 

 
        </span> 
 
        <input class="done" type="checkbox"> 
 
       </td> 
 

 

 
       <td> 
 
        <span style="min-width:100px;min-height:20px;margin-left:0px">Please hide this on check</span> 
 

 
       </td> 
 

 
      </tr> 
 
     </tbody> 
 
    </table> 
 

 
</li>

+1

'.hide'缺少'()'。投票结束作为错别字 –

回答

3

你犯了一个错字:调用函数的hide()代替.hide

$(".done").on("change", function() { 
 
    if ($(this).is(":checked")) { 
 
    $(this).closest(".panel").hide(); 
 
    } 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 

 
<li class="panel" style="background:#f4f4f4;"> 
 
    <table style="width:100%"> 
 
     <tbody> 
 
      <tr> 
 
       <td style="width:45px"> 
 
        <span class="handle ui-sortable-handle"> 
 

 
        </span> 
 
        <input class="done" type="checkbox"> 
 
       </td> 
 

 

 
       <td> 
 
        <span style="min-width:100px;min-height:20px;margin-left:0px">Please hide this on check</span> 
 

 
       </td> 
 

 
      </tr> 
 
     </tbody> 
 
    </table> 
 

 
</li>

+0

哦!我非常专注,以至于我只是完全忽略了这个“最接近”的东西是错误的... – Jarla

+0

哈哈,没问题,请问如果现在可行,请接受我的回答吗? –

0

叫我傻,但你忘了隐藏**()**括号jajajja,这里是一个demo

$(".done").on("change", function() { 
console.log($(this), $(this).closest(".panel")); 
    if ($(this).is(":checked")) { 
    $(this).closest(".panel").hide(); 
    } 
}); 
相关问题