用jQuery重复元素

编程入门 行业动态 更新时间:2024-10-11 19:13:33
本文介绍了用jQuery重复元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我确信这对于合适的人来说是显而易见的,但我怎样才能用jQuery重复一个元素?从本质上讲,我希望jQuery无限次地重复一个内联元素;就像你会使用CSS重复背景纹理的图形一样。我一直在研究.clone()和.each(),但是可以真正使用一些指针。

谢谢!

  • J
  • ul>

    解决方案

    http:// jsfiddle / 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

    解决方案

    jsfiddle/gRTTJ/

    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重复元素

本文发布于:2023-11-11 05:14:42,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:元素   jQuery

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!