【问题标题】:how to move a "li" tag into another "ul" tag without removing the first "li"? [closed]如何在不删除第一个“li”的情况下将“li”标签移动到另一个“ul”标签中? [关闭]
【发布时间】:2020-11-11 12:44:42
【问题描述】:

如何在不删除第一个“li”的情况下将“li”标签移动到另一个“UL”标签中?

 $(document).ready(function () {
        $("#id").click(function () {
            $("#id li").last().replace('#id li');
        });
    });

我也使用了这段代码,但没有用。

【问题讨论】:

  • 您好 parsa,欢迎来到 SO。你的问题很简单。考虑添加更多关于结果应该是什么以及究竟是什么不起作用的详细信息。还要确保包含您的 HTML 并创建一个stacksnippet,我们可以在其中运行您的代码。阅读how to create a Minimal, reproducible example 了解有关您的 sn-p 的指南。
  • 大多数 jquery 方法移动现有元素 - 所以使用 clone() 创建副本(或使用 .html()
  • clone() 也许?

标签: javascript html jquery css frontend


【解决方案1】:

您可以使用 jquerys clone() 方法“复制”元素

 $(document).ready(function () {
        $("#id").click(function () {
            $("#id li").last().clone().appendTo('.anotherElement')
        });
    });

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-01-24
    • 1970-01-01
    • 2013-04-15
    • 2012-03-13
    • 2013-04-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多