当第一个div达到一定限制时,如何删除它?

发布于 2024-09-19 07:51:52 字数 116 浏览 2 评论 0原文

谁能指导我删除第一个 div,当有 5 个 div 时,

我正在克隆一个文本框,用户可以添加多个文本框 但是当它达到 5 时,我应该自动删除第一个文本框并在节点末尾添加另一个文本框

谢谢

Can anyone guide me to delete the first div, when there are 5 div's

I'm cloning a text box, users can add multiple textbox's
but when it reaches to 5, i should automatically delete the first textbox and add another at the end of the node

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

温折酒 2024-09-26 07:51:52

使用 jQuery:

您需要计算所有这些 div 并删除第一个:

count = $('#container div').length;
if (count > 5) {
    $('#container div:first').remove();
}

要添加新的 div:

$('#container').append('<div ...><textbox...></textbox></div>');

With jQuery:

You need to count all of these divs and remove first one:

count = $('#container div').length;
if (count > 5) {
    $('#container div:first').remove();
}

To add new div:

$('#container').append('<div ...><textbox...></textbox></div>');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文