用jQuery重复元素 [英] Repeating elements with jQuery

查看:74
本文介绍了用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

    解决方案

    http://jsfiddle.net/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重复元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆