0

我如何隐藏所有<li>未检查的元素。最好的方法是什么?Ruby 还是 JavaScript?

<h3>Stores Offered In</h3>
  <ul class="multi-column-checkbox">
    <% for store in Store.all %>
        <li><%= check_box_tag "idea[store_ids][]", store.id,  
@idea.stores.include?(store) %> <%= store.name %></li>
    <% end %>
  </ul>
  <br />
4

2 回答 2

2

由于这已被标记为 jQuery,我会试试这个:

$('.multi-column-checkbox li input[type="checkbox"]:not(:checked)').parent().hide();
于 2013-10-01T21:30:10.693 回答
0

先看看本教程的基础, https://bytutorial.com/blogs/jquery/jquery-get-selected-checkboxes

当您为每个 for 循环迭代时,您可以抓住父级并将其隐藏.. 使用这个。注意:$(this) 表示选中的复选框。并且 .parent 将代表您的案例中的 li 。

$(this).parent.hide();

于 2013-10-01T21:33:08.603 回答