1
我想獲取選定的元素,然後在少數地方插入它的副本。如何在jQuery中獲取整個元素的副本?
var template = $("#info-" + country + " > .stats > .template").clone();
$(template).insertBefore("#info-" + country + " > .stats > .template");
我做錯了,它不復制元素並插入它?
P.S.我選擇要複製的元素是display:none。
嗯,試過第三個例子,什麼也沒有發生。現場示例:http://apps.s tarchat.ee/stats.php – Rihards 2010-10-29 17:18:41
@Richards - 你的選擇器與你的標記不匹配,裏面有一個'.map',像這樣:'$(「#instance-」+ country +「> .content> .stats > .map> .template「)' – 2010-10-29 17:25:11
Bwaah,我甚至沒有注意到它 - 我認爲它會檢查所有的孩子,不是嗎?十分感謝! :) – Rihards 2010-10-29 17:29:20