我試圖克隆使用jQuery的無線電組。我的克隆代碼:jQuery的克隆ID更新
$("#btnAddAnotherLocation").live("click", function(){
cloneIndexLocation++;
$("#clonedInputLocation0").clone()
.appendTo("#clonedInputsLocation")
.attr("id", "clonedInputLocation" + cloneIndexLocation)
.find("*").each(function(){
var id = this.id || "";
var match = id.match(regex) || [];
if(match.length == 5){
this.id = match[1]+(cloneIndexLocation);
}
}).end();
});
我cloneDiv內容是:
<div id="clonedInputLocation0" class="clonedInputLocation" style="display: none;">
<div class="formLocationWrapper">
<label class="labelRadioBlack labelContainsInput" for="locationInNear0">
<input name="locationInNearRadio[]" id="locationInNear0" value="" type="radio" />
In or near
</label>
<div class="inNearTextWrapper">
<input class="myWirrlMediumFormField" type="text" name="txtLocationInNear[]" value="" />
</div>
</div>
<div class="formLocationWrapper">
<label class="labelRadioBlack labelContainsInput" for="locationAnywhereIn0">
<input name="locationInNearRadio[]" id="locationAnywhereIn0" value="" type="radio" checked="checked" />
Anywhere in
</label>
</div>
<div class="" id="clonedInputLocationRemove0">
<a href="javascript: void(0);">Remove location</a>
</div>
</div>
對不起尋找它的凌亂,它實際上是有很多清潔在我的編輯。
的問題是不是克隆的實際內容,這是工作的罰款。問題是,我需要更新的無線電組名字locationInNearRadio [cloneIndexLocation]和ID的和的屬性被命名爲locationInNearcloneIndexLocation其中cloneIndexLocation是下一個增量。
我有這樣的代碼工作的一組選擇場的哪一個更新所有的ID給clonedIndex數量,但由於某種原因,我不能得到相同的代碼,甚至更新的無線電組ID的。
乾杯
什麼是您的正則表達式看起來像和你確定使用+1與字符串遞增數或只是增加了「1」的ID的結束?在jsFiddle.net上的演示將會更有幫助。 – Mottie