gpt4 book ai didi

jquery - 如何在下拉列表中的最后一个li之前附加

转载 作者:行者123 更新时间:2023-12-01 00:05:21 25 4
gpt4 key购买 nike

我正在使用以下表单生成器 ( http://dontlink.me/formbuilder/ ) 并对其进行大量更改以按照我想要的方式工作。

我希望它做的一件事是,当您添加新的表单字段时,我希望将该表单字段放置在列表的底部......目前它们放置在顶部。

这是将新 li 添加到列表中的代码...我已将其简化为实际执行添加的部分...

var result = '<li>The new form field code goes here....</li>';
var into = $("#form_builder_panel ol");
$(into).prepend(result);

出于某种原因,默认情况下他们会在代码中添加一个“li”标签,并为其指定一个“last-child”类。

<div id="form_builder_panel">
<form method="post" action="preview.php" class="fancy">

<fieldset class='sml'>
<legend>Built Form</legend>
<ol>
<li class="last-child"></li>
</ol>
</fieldset>

现在我尝试将第三行代码更改为以下内容:

$(into).append(result);

但是这会将“最后一个子”li 放在顶部,并且脚本停止工作...

所以我的问题是,如何才能将新的 li 附加到列表中,但将其添加到“最后一个子”li 之上?

希望我说得有道理:)

最佳答案

怎么样

before function

Insert content before each of the matched elements.

$(".last-child").before(result);

如果您想每次将其附加为最后一个 li,则从 li 中删除类“last-child”并使用 :last-child选择器就像

$(".sml li:last-child").after ( result );

关于jquery - 如何在下拉列表中的最后一个li之前附加,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1502003/

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