在clone appendchild之后删除html标记id

时间:2013-10-25 01:27:40

标签: jquery

我试图在克隆后删除一个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之后放置这个,然后在克隆方法上再次调用它,但是没有工作:

    $('input#datepicker-example7-start').RemoveAttr('id');
    $('input#datepicker-example7-end').RemoveAttr('id');

    $('input.dp-start:last').RemoveAttr('id');
    $('input.dp-end:last').RemoveAttr('id');

我需要的是在头标记上调用datepicker后删除id,以便当我单击添加行提交按钮并调用克隆方法时,它不会克隆带有id的输入标记,并且不会再次加载日历图标。 ..似乎日历图标与每个克隆重叠,这使得它无法点击,只有在点击文本框时才会加载日历(第一行,文本框和日历图标都可点击)

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

我不太了解这个问题,但如果您只想尝试删除ID,请尝试使用

 $('input.dp-start:last').attr("id","");

 $('input.dp-start:last').removeAttr('id');