【发布时间】:2014-07-04 11:08:01
【问题描述】:
我有一个each 循环,其中每个循环元素都具有以下 html 结构:
<li>
<p>Text</p>
<form>...</form>
</li>
在循环中,我创建了一个<span> 元素,我想将它插入到<p> 和<form> 元素之间的每个循环元素中。但我不知道如何访问this 中的元素,我只知道如何在li 的开头(prepend)和结尾('append')插入它,但不在@987654331 之间@ 和<form>。
这是我的代码:
function calculation(elements) {
$(elements).each(function() {
...
var output = $('<span>').addClass('durationValue').html('Some Values..');
$(this).append(output);
});
}
【问题讨论】:
-
你能做一个小提琴吗?
-
您可以使用 before() 或 after() 来执行追加。 api.jquery.com/beforeapi.jquery.com/after
标签: jquery html loops this each