gpt4 book ai didi

javascript - 使用 jQuery 删除空
  • 转载 作者:行者123 更新时间:2023-11-28 11:13:30 25 4
    gpt4 key购买 nike

    Possible Duplicate:
    Remove Empty elements with jQuery

    我想删除空 <li>使用 jQuery。我正在尝试执行此操作,但我的代码未按照我的要求运行。我的代码如下所示。

    脚本

    $(document).ready(function(e) {
    $('#u li').each(function() {
    if($(this).html(' ')) {
    $(this).remove();
    }
    });
    });

    HTML

    <ul id="u">
    <li>hi</li>
    <li></li>
    </ul>

    最佳答案

    应该就这么简单:

    $('#u li:empty').remove()

    关于javascript - 使用 jQuery 删除空 <li>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11579807/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com