我有一個帶有標籤和其他東西的div。該標籤包含以下內容:「步驟1」。更改相同名稱的類嵌套的內容是具有相同類的div
<div class="methodContainer">
<label class="steps">Step 1:</label>
<textarea name="step" class="stepMethod glowingBorder"></textarea>
<div class="removeMethod" title="Click to remove this ingredient">
</div>
</div>
如果你點擊我使用jQuery完全相同的副本,添加爲代碼在這裏,並把它的代碼背後的頁面上的其他股利。
$('.plusMethod').click(function() {
$('<div class="methodContainer"><label class="steps">Step 1:</label><textarea name="step" class="stepMethod glowingBorder"></textarea><div class="removeMethod" title="Click to remove this ingredient"></div></div>').appendTo('.partMethod');
}
這可以根據用戶需要多次重複。
但是,這樣所有帶有類步驟的標籤將具有內容:「步驟1」。我希望第二個有「第2步」,第3個「第3步」等。我該怎麼做呢?
!!!!編輯!!!!
感謝您的快速解答!但我忘了說我也有可能刪除一部分。我這樣做,
$('.removeMethod').live('click', function() {
$(this).parents('.methodContainer').remove();
}
所以,如果我用阿倫P佐尼的其中工程:)每條添加的內容將與步驟1,2,3,等被貼上了答案。但是當用戶刪除例如第二步時,現在的步驟將如下所示:1,3,4等等。我如何解決這個問題?
謝謝,我更新了我的問題,你可以看看這個? –
@NiekNijland查看更新後的答案 –