Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jQuery:复制嵌入式Tweet';s HTML_Jquery_Twitter_Embed_Tweets - Fatal编程技术网

jQuery:复制嵌入式Tweet';s HTML

jQuery:复制嵌入式Tweet';s HTML,jquery,twitter,embed,tweets,Jquery,Twitter,Embed,Tweets,假设我在div中嵌入了一条tweet: <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/30

假设我在div中嵌入了一条tweet:

<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>
这里有一个

这不起作用,它让我:(


有什么解决方法吗?

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

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

jsiddle:

脚本异步加载,因此当您尝试复制内容时,可能会发生尚未加载的情况


当脚本的
load
-事件触发时复制内容:

如果我将你的小提琴切换到jQuery 1.9并运行,它对我有效。小提琴链接修改为jQuery 1.9,仍然对我无效(显示为空白)。我使用的是最新版本的Chrome。你看到两条完全相同的嵌入推文吗?我想更好的例子是->我想复制嵌入推文的外观,而不仅仅是文本。然而,这很有趣,并教会了我一些东西,因此你得到了我的支持:)它应该按需要显示,而不是缓存问题,尝试在脚本src中添加一个变化的参数(例如时间戳),这似乎是可行的,但是尝试将复制的tweet插入到div中怎么样?为什么您坚持使用HTML而不是克隆实际对象?有些HTML无法直接复制(ID、事件处理程序等冲突)。@DougieBear-如果你想在插入之前/之后获得内容,你可以这样做:哈哈,我不想坚持任何东西,只是想把推文放在我用javascript创建的div中,然后将该div添加到页面:@DougieBear-我在之前的评论中提供了一种更好的方法。
var tweetCopy = $("#tweet").clone();
$("#tweet-insert").append(tweetCopy);