用jQuery重复元素 [英] Repeating elements with jQuery
问题描述
我确信这对于合适的人来说是显而易见的,但我怎样才能用jQuery重复一个元素?从本质上讲,我希望jQuery无限次地重复一个内联元素;就像你会使用CSS重复背景纹理的图形一样。我一直在研究.clone()和.each(),但是可以真正使用一些指针。
谢谢!
- J
ul>
http:// jsfiddle .net / gRTTJ /
关键字:
$( #重复)附加($( foobar的。)克隆());
虽然如果你想要它无限的话,它将是一个无限循环(显然)并且不是太有用。
一个稍微更合理的版本无限运行:
函数重复()
{
$(#repeating)。append($(。foobar:first)。clone());
$(function(){
setInterval(repeat,1000);
});
I'm sure this is going to be obvious to the right person, but how can I repeat an element with jQuery? Esentially I want jQuery to repeat an inline element an infinite number of times; like you would use CSS to repeat a graphic for a background texture. I've been researching .clone() and .each() but but could really use some pointers.
Thanks!
- J
Key line:
$("#repeating").append($(".foobar").clone());
Although if you want it infinitely, it will be an infinite loop (obviously) and not be too useful.
A slightly more reasonable version that runs infinitely:
function repeat()
{
$("#repeating").append($(".foobar:first").clone());
}
$(function () {
setInterval(repeat, 1000);
});
这篇关于用jQuery重复元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!