开发者

remove name from dynamically created hidden input

I have a div that is being duplicated dynamically. After duping it, I need to remove the name from the hidden input only, but can't seem to be able to select it only. The majority of the file is prototype, but I have jQuery at my disposal (jq).

I have managed to get the name to disappear, but it clears them all out, I only want it cleared on the duplicated div.

Help appreciated.

function dupField(fieldName,container,dupediv){
    var container = $(container);
    var dupedDiv = $(dupediv).cloneNode(true);
    var totalins=jq("#MI_name > div").size();
    newNode=document.createElement('div');
    newNode.innerHTML=dupedDiv.innerHTML;
    newNode.setAttribute('id',dupediv+totalins);
    newNode.setAttribute('class','MI_inz');
    var inputs_txt = newNode.getElementsByTagName('input');
    var x = jq('#MI_label').val();
    for(j=0;j<inputs_txt.length;j++){//change text field names
            var nameNow = inputs_txt[j].name;
            var newName = nameNow+totalins;
            inputs_txt[j].name=newName;
            inputs_txt[j].value='';
    }
    container.appendChild(newNode);
    var nn=jq('newNode:hidden');//jQuery - this selects all the hidden's in the form-no good-only want to change hidden input in newNode
    var hid=jq(nn).attr('name','');
}

It's the part after appendChild.

some of the other things I've tried:

var nn=jq('newNode:input(:hidden)');

-

var nn=jq(newNode).attr('id');
jq开发者_高级运维(nn+':hidden').attr('name','');

etc...

I'm sure it's simple, but I can't get it...


For an input where attribute type equals hidden:

jq(newNode).find('input[type=hidden]');


container.appendChild(newNode);
var nn=jq('newNode:hidden');
var hid=jq(nn).attr('name','');

You don't need to look up your new node. You already have a reference to it. Just use it to remove the name.

jq(newNode).attr('name', '');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜