我试图在克隆后删除一个 id 并且它不工作我有这个:
头:
$(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;
我已经尝试在调用 datepicker 之后并在 clone 方法上再次调用它之前放置它,但无法正常工作:
$('input#datepicker-example7-start').RemoveAttr('id');
$('input#datepicker-example7-end').RemoveAttr('id');
和
$('input.dp-start:last').RemoveAttr('id');
$('input.dp-end:last').RemoveAttr('id');
我需要的是在调用 head 标签上的 datepicker 之后删除 id,这样当我单击添加行提交按钮并调用 clone 方法时,它不会克隆带有 id 的输入标签,也不会再次加载日历图标......它似乎日历图标与每个克隆重叠,这使得它无法点击,并且只有在点击文本框时才会加载日历(第一行,文本框和日历图标都是可点击的)
感谢帮助!