我有克隆HTML數據在這裏我需要刪除一條記錄,然後我需要從該取消記錄獲得ID。 這裏是我的html代碼:如何獲得克隆HTML隱藏ID,而點擊取消按鈕
<div id="Allergies" class="clone">
<div class="copy">
<input type="hidden" id="allergyId" value="">
/*rest of the code will be the html data*/
<a class="addallergy" id="addallergy">Save and Add Allergy</a>
<a class="removeallergy" id="removeallergy">Cancel</a>
</div>
<div>
這裏是我的javascript代碼:
var p=$('.copy').length;
var h=0;
for(var i=0 ; i<data.allergies.length ; i++){
var cloned = $(".copy:first").clone(true)
. .appendTo('#Allergies').addClass("childAllergyClass" + (i + 1));
$(".childAllergyClass"+ ++h+" #allergyId").val(data.allergies[i].allergyId);
}
現在我的HTML代碼將是:
<div id="Allergies" class="clone">
<div class="copy childAllergyClass1">
<input type="hidden" id="allergyId" value="123">
/*rest of the code will be the html data*/
<a class="addallergy" id="addallergy">Save and Add Allergy</a>
<a class="removeallergy" id="removeallergy">Cancel</a>
</div>
<div class="copy childAllergyClass2">
<input type="hidden" id="allergyId" value="124">
/*rest of the code will be the html data*/
<a class="addallergy" id="addallergy">Save and Add Allergy</a>
<a class="removeallergy" id="removeallergy">Cancel</a>
</div>
<div>
如果我們有長度爲2個那麼雙過敏顯示在UI中。如果我點擊取消,當前的記錄將通過使用代碼消失
$(".removeallergy").click(function(e) {
$(this).closest(".copy").fadeOut("slow", function(){
$(this).remove();
});
});
然後我需要特定的記錄ID爲非活動狀態數據庫中的當前記錄狀態。
請幫助我如何從取消記錄中獲得id或其他任何更好的想法來使數據庫中的記錄無效。
題外話:這是「生命威脅* en * ing「。 – 2014-09-10 13:02:20
你的問題到底是什麼? – 2014-09-10 13:04:49
你有兩個輸入元素具有相同的ID? – chridam 2014-09-10 13:05:08