function switch(){
$('#get1').clone();
$('#get2').replaceWith($('#get1'));
};
我在這裏預計#get1的一個副本會保留在原始位置,但會發生什麼:它會消失,因爲沒有被克隆。
因此,我希望#get2替換爲#get1的COPY,而不是原件。如何用另一個副本替換一個div?
function switch(){
$('#get1').clone();
$('#get2').replaceWith($('#get1'));
};
我在這裏預計#get1的一個副本會保留在原始位置,但會發生什麼:它會消失,因爲沒有被克隆。
因此,我希望#get2替換爲#get1的COPY,而不是原件。如何用另一個副本替換一個div?
你是creating clone but not using clone
,而是使用orininal對象。你必須assing克隆對象的一些對象,並使用在replaceWith功能,
function switch(){
yourClone = $('#get1').clone();
$('#get2').replaceWith(yourClone);
};
首先,不要使用「開關」的,因爲保留字的變量名稱。
反正,這裏是我的回答
function doSwitch(){
var $get1 = $('#get1').clone();
$('#get2').replaceWith($get1);
}
設置克隆對象到一個變量來使用。
Adil,非常好,非常感謝。解決了。 – Alegro
不客氣。 – Adil
'yourClone'作爲一個全局變量?爲什麼不''$('#get2')。replaceWith($('#get1')。clone());' – nnnnnn