0

我需要克隆元素的值空白。

下面的代码运行良好,但它正在克隆值;无法弄清楚如何阻止它。

var Move =  {

    copy    :   function(e, target) { 
                var eId     = $(e);
                var copyE   = eId.cloneNode(true);
                var cLength = copyE.childNodes.length -1;
                copyE.id    = e+'-copy';

                for(var i = 0; cLength >= i;  i++) {
                    if(copyE.childNodes[i].id) {
                    var cNode   = copyE.childNodes[i];
                    var firstId = cNode.id;
                    cNode.value = '';
                    cNode.id    = firstId+'-copy'; }
                }

                $('txtWoundCareLocation').value="";
                $(target).appendChild(copyE);
                },
    element :   function(e, target, type)   {
                var eId =   $(e);
                if(type == 'move') { $(target).appendChild(eId); }

                else if(type == 'copy')     { 
                    this.copy(e, target);
                }
                }
}
4

2 回答 2

0

把它放在副本的末尾:

$(cnode.id).value="";
于 2012-07-17T05:56:01.307 回答
0

eId.cloneNode(true) returns an jQuery object, not a HTMLNode. Thus copyE contains a jQuery object not an HTMLNode. You are using it like an HTMLNode however. This should introduce problems.

Also, setting value on a jQuery object (as in $('txtWoundCareLocation').value="") will not alter the HTMLNode value. Instead, you should call the jQuery.val method to unset the HTMLNode value: $('txtWoundCareLocation').val('');

I thought this was about jQuery. I'm not into prototype, sorry.

于 2012-07-06T08:50:03.053 回答