jQuery - 是否可以复制和粘贴HTML? [英] jQuery - Is it possible copy and paste HTML?

查看:63
本文介绍了jQuery - 是否可以复制和粘贴HTML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

jQuery - 可以复制和粘贴HTML吗?

jQuery - Is it possible copy and paste HTML?

从一个例子开始,如果我有这行HTML:

Starting with an example, if I have this lines of HTML :

<div id="divToMove">
    ... somethings like 100 lines of code ...
</div>

我想知道我是否可以使用此div并复制和粘贴多次...

i'd like to know if I can take this div and copy and paste many times...

我试图把一个jQuery / JS函数从javascript添加到HTML页面,但似乎这个过程太慢了。也许复制和粘贴(如果可能的话)更快...
有些帮助吗?谢谢

I tried to put a jQuery/JS function that "add" this code from javascript to the HTML page, but seems that is too slower as process. Maybe a copy and paste (if possible) is faster... Some helps? Thanks

推荐答案

这样的事情?

HTML

<input type="button" id="copy" value=" copy "/>

<div id="content">
    <span>here's a span</span>
    <div>and a div</div>
</div>

jQuery

$(function()  {
    $('#copy').click(function(){
        var content = $('#content').html();
        var newdiv = $("<div>");
        newdiv.html(content);
        $('#content').after(newdiv);
    });
  });

行动中:
http://jsfiddle.net/Town/5q2CK/

这篇关于jQuery - 是否可以复制和粘贴HTML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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