0
我有以下HTML内容:如何使用jquery克隆html内容?
<div data-test='sectionA'>
<input type="text" />
<strong>sfdsfds</strong>
<p>dffdfdsf</p>
</div>
我需要克隆只能从上面的html内容的strong
和p
元素。这里是我的尝试:
首先,我需要确定的部分:
if($("div").data("test") == "sectionA")
{
$(this).children().not("input").each(function()
{
alert($(this).html().clone());
/* firefox says clone is not a function
and I'm not getting <strong>dfadfa</strong>
or the <p>sfdasdfsd</p> clone copy */
});
}
,但我认为'的.html()'返回一个字符串。你只能克隆HTML元素,而不是字符串。尝试删除 – Oriol 2013-02-10 20:43:59
'html'函数返回字符串而不是节点/对象,所以你没有什么可以克隆的。 – 2013-02-10 20:44:22
克隆副本应该是评论的一部分 – 2013-02-10 20:44:50