Html CSS使li在没有';不包含复选框

Html CSS使li在没有';不包含复选框,html,css,woocommerce,Html,Css,Woocommerce,我有一个ul和3个li,每个都包含一个复选框和一个its标签(Woocommerce运输方法)。如何设置display:none没有选中复选框的li? 以下是html,在具体示例中,我想隐藏除免费送货之外的所有内容: <ul id="shipping_method" class="woocommerce-shipping-methods"> <li style=" "> <div c

我有一个
ul
和3个
li
,每个都包含一个复选框和一个its标签(Woocommerce运输方法)。如何设置
display:none
没有选中复选框的
li
? 以下是html,在具体示例中,我想隐藏除免费送货之外的所有内容:

<ul id="shipping_method" class="woocommerce-shipping-methods">
    <li style="
">
        <div class="porto-radio ">
            <input type="radio" name="shipping_method[0]" data-index="0" id="shipping_method_0_flat_rate8" value="flat_rate:8" class="shipping_method porto-control-input">
                <label class="porto-control-label text-capitalize font-weight-normal" for="shipping_method_0_flat_rate8">Flat rate 5: 
                    <span class="woocommerce-Price-amount amount">
                        <bdi>
                            <span class="woocommerce-Price-currencySymbol">€</span>5,00
                        </bdi>
                    </span>
                </label>
            </div>
        </li>
        <li>
            <div class="porto-radio ">
                <input type="radio" name="shipping_method[0]" data-index="0" id="shipping_method_0_flat_rate9" value="flat_rate:9" class="shipping_method porto-control-input">
                    <label class="porto-control-label text-capitalize font-weight-normal" for="shipping_method_0_flat_rate9">Flat rate 10: 
                        <span class="woocommerce-Price-amount amount">
                            <bdi>
                                <span class="woocommerce-Price-currencySymbol">€</span>10,00
                            </bdi>
                        </span>
                    </label>
                </div>
            </li>
            <li>
                <div class="porto-radio ">
                    <input type="radio" name="shipping_method[0]" data-index="0" id="shipping_method_0_free_shipping10" value="free_shipping:10" class="shipping_method porto-control-input" checked="checked">
                        <label class="porto-control-label text-capitalize font-weight-normal" for="shipping_method_0_free_shipping10">Free shipping</label>
                    </div>
                </li>
            </ul>
  • 统一费率5: €5,00
  • 统一费率10: €10,00
  • 免费送货

您可以使用jQuery来实现这一点

  • 首先选择除选中复选框之外的所有复选框
  • 然后获取父级
    li
    ,并向其添加CSS
  • $(“文档”).ready(函数(){
    var$uncheckedLi=$(“ul li输入:非([选中]))。父项(“li”);
    $uncheckedLi.css(“显示”、“无”);
    });
    
    
    
    • 统一费率5: €5,00
    • 统一费率10: €10,00
    • 免费送货

    您可以对
    li
    内的所有收音机使用
    过滤器
    ,如果未选中则隐藏

    $('li input[type=“radio”])。过滤器(函数(){
    return!$(this).is(“:checked”);
    }).closest('li').hide()
    
    
    
    • 统一费率5: €5,00
    • 统一费率10: €10,00
    • 免费送货

    您的意思是不选中radio not复选框只有在您可以修改标记结构的情况下,才可以在css中使用此复选框。很好,它可以工作!但是当通过ajax刷新
    ul
    时,它能工作吗?好的,它能工作!但是,当通过ajax刷新整个系统时,是否有可能使其工作?是的,这是可能的。请分享你的ajax代码。它不是我的,它是woocommerce实现。如果它是我的,我可以投入成功。。。