克隆每个元素后添加换行符
$('.footnote').clone().appendTo('#allfootnotes').append('<br>');
我在整个页面中有一堆 .footnote
元素,在页面底部我想列出页面上的所有脚注。因此每个脚注都会被克隆到#allfootnotes
。我试图在 #allfootnotes
元素中的每个 .footnote
之后放置一个换行符,这样它们就不会混在一起。
一旦将每个 .footnote
克隆到 #allfootnotes
后,如何在每个 .footnote
之后应用换行符?
这是最好的方法吗?在每个 .footnote
中有 2 个 span 标签,一个用于标题,一个用于脚注内容(不知道这是否重要)。
$('.footnote').clone().appendTo('#allfootnotes').append('<br>');
I have a bunch of .footnote
elements all through the page, at the bottom of the page I want to list all of the footnotes on the page. So each footnote will be cloned to #allfootnotes
. I'm trying to place a line break after each .footnote
in the #allfootnotes
element, so they're not all jumbled together.
How would I apply the line break after each .footnote
once it's been cloned to #allfootnotes
?
And is this the best way to do it? In each .footnote
there's 2 span tags, one for the title, and one for the footnote content(don't know if that matters or not).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
听起来您可以使用 CSS 来执行此操作,
具体取决于您的情况,您可能需要使用
display: block;
将 .footnote 设为块级元素It sounds like you could use CSS to do this
Depending on your situation you may need to make .footnote a block level element with
display: block;
DEMO
如果您使用 XHTML,则应该是 <代码>
DEMO
If you use XHTML than it should be
<br />
如果有如您所说的那么多脚注,缓存
$('#allfootnotes')
将减少浏览器的负载。希望这有帮助
If there are as many foot notes as you say cacheing your
$('#allfootnotes')
will decrease load on the browser.Hope this helps
编辑请参阅 roXon 的答案。这比自己迭代脚注要干净得多。
EDIT Please see roXon's answer. It's way cleaner than iterating over footnotes yourself.