我嘗試刪除ID被克隆後和其沒有工作,我有這樣的:刪除HTML標籤ID後,克隆的appendChild
頭:
$(window).load(function() {
$('#datepicker-example7-start').Zebra_DatePicker({
direction: false,
pair: $('#datepicker-example7-end')
});
$('#datepicker-example7-end').Zebra_DatePicker({
direction: true
});
});
體:
<input id="datepicker-example7-start" class="dp-start" type="text" name="datefrom[]" style="width:100%" />
<input id="datepicker-example7-end" class="dp-end" type="text" name="dateto[]" style="width:100%"/>
和我的jquery克隆是:
var elements, templateRow, rowCount, row, className, newRow, element;
var i, s, t;
/* Get and count all "tr" elements with class="row". The last one will
* be serve as a template. */
if (!document.getElementsByTagName)
return false; /* DOM not supported */
elements = document.getElementsByTagName("tr");
templateRow = null;
rowCount = 0;
for (i = 0; i < elements.length; i++) {
row = elements.item(i);
/* Get the "class" attribute of the row. */
className = null;
if (row.getAttribute)
className = row.getAttribute('class');
if (className === null && row.attributes) { // MSIE 5
/* getAttribute('class') always returns null on MSIE 5, and
* row.attributes doesn't work on Firefox 1.0. Go figure. */
className = row.attributes['class'];
if (className && typeof(className) === 'object' && className.value) {
// MSIE 6
className = className.value;
}
}
/* This is not one of the rows we're looking for. Move along. */
if (className !== "row_to_clone_fw_emp")
continue;
/* This *is* a row we're looking for. */
templateRow = row;
rowCount++;
}
if (templateRow === null)
return false; /* Couldn't find a template row. */
/* Make a copy of the template row */
newRow = templateRow.cloneNode(true);
/* Change the form variables e.g. price[x] -> price[rowCount] */
elements = newRow.getElementsByTagName("input");
for (i = 0; i < elements.length; i++) {
element = elements.item(i);
s = null;
s = element.getAttribute("name");
if (s === null)
continue;
t = s.split("[");
if (t.length < 2)
continue;
s = t[0] + "[" + rowCount.toString() + "]";
element.setAttribute("name", s);
element.value = "";
/* element.find('#datepicker-example7-start').removeAttr('id');
element.find('#datepicker-example7-end').removeAttr('id'); */
}
templateRow.parentNode.appendChild(newRow);
$('.dp-start:last').Zebra_DatePicker({
direction: false,
pair: $('.dp-end:last')
});
$('.dp-end:last').Zebra_DatePicker({
direction: true
});
return true;
我已經打過電話上頭上的日期選擇器後,再調用它的clone方法,但AINT工作之前放置這樣的:
$('input#datepicker-example7-start').RemoveAttr('id');
$('input#datepicker-example7-end').RemoveAttr('id');
和
$('input.dp-start:last').RemoveAttr('id');
$('input.dp-end:last').RemoveAttr('id');
我需要的是刪除ID後調用head標籤上的日期選擇器,以便當我點擊添加行提交按鈕並調用克隆方法時,它不會克隆帶有ID的輸入標籤,並且不會再次加載日曆圖標......看起來,日曆圖標重疊每一個克隆都使它不復雜只有點擊文本框才能加載kable和日曆(第一行,文本框和日曆圖標均可點擊)
感謝您的幫助!
JavaScript是區分大小寫的。它是'removeAttr',而不是'RemoveAttr'。 – j08691
它總是有助於檢查控制檯。你可能會被拋出一個錯誤,就像方法'RemoveAttr'不存在或者喜歡的一樣。 – Terry
已經改爲小寫,仍然不能正常工作 – jake