作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用以下表单生成器 ( 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 之上?
希望我说得有道理:)
最佳答案
怎么样
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/
我是一名优秀的程序员,十分优秀!