jQuery:复制嵌入式Tweet的HTML [英] jQuery: Copying an Embedded Tweet's HTML

查看:146
本文介绍了jQuery:复制嵌入式Tweet的HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我在div中有一个嵌入式推文:

Say I have an embedded tweet inside a div:

<div id="tweet">
    <blockquote class="twitter-tweet"><p>A lion would never cheat on his wife. But a Tiger Wood.</p>&mdash; Puns (@omgthatspunny) <a href="https://twitter.com/omgthatspunny/status/301482080490115072">February 13, 2013</a></blockquote>
    <script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>
</div>

<div id="tweet-insert"></div>

我想复制该推文并将其插入另一个div:

And I want to copy the tweet and insert it into another div:

var tweetHtml = $("#tweet").html();
$("#tweet-insert").html(tweetHtml);

这里是 小提琴 .

Here is a fiddle.

这不起作用,这使我:(

有什么想法要解决吗?

推荐答案

您可以像这样使用jQuery的.clone():

You can use jQuery's .clone() like this:

var tweetCopy = $("#tweet").clone();
$("#tweet-insert").append(tweetCopy);

jsFiddle: http://jsfiddle.net/jfriend00/9Segq/

jsFiddle: http://jsfiddle.net/jfriend00/9Segq/

这篇关于jQuery:复制嵌入式Tweet的HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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