Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
javascript setAttribute(“name”,newname)不更改文本框;s name它创建submitName_Javascript_Html - Fatal编程技术网

javascript setAttribute(“name”,newname)不更改文本框;s name它创建submitName

javascript setAttribute(“name”,newname)不更改文本框;s name它创建submitName,javascript,html,Javascript,Html,我使用此函数在表中创建新行 function addRow(obj) { var table = document.getElementById("table2"); var rowCount = table.rows.length-1; var row = table.insertRow(rowCount); var nowrownum = table.rows.length-1;

我使用此函数在表中创建新行

   function addRow(obj) 
    {
            var table = document.getElementById("table2");
            var rowCount = table.rows.length-1;
            var row = table.insertRow(rowCount);
            var nowrownum = table.rows.length-1;        
            var colCount = table.rows[2].cells.length;
            for(var i=0; i<colCount; i++) {
                var newcell = row.insertCell(i);
                newcell.innerHTML = table.rows[2].cells[i].innerHTML;
                newcell.style.cssText = table.rows[2].cells[i].style.cssText;

//Here is problem
                newcell.childNodes[0].setAttribute("name",table.rows[2].cells[i].childNodes[0].getAttribute("name")+nowrownum);
//End here                 
                newcell.childNodes[0].id    = table.rows[2].cells[i].childNodes[0].id+nowrownum;
                switch(newcell.childNodes[0].type)  
                {
                    case "text":
                            newcell.childNodes[0].value = "";
                            break;
                }
            }
            obj.style.visibility = "hidden"; //to hide current button
    }
函数addRow(obj)
{
var table=document.getElementById(“表2”);
var rowCount=table.rows.length-1;
var row=table.insertRow(rowCount);
var nowrownum=table.rows.length-1;
var colCount=table.rows[2].cells.length;

对于(var i=0;i如何更改id..使用相同的代码更改属性名称..我的意思是

newcell.childNodes[0].name = table.rows[2].cells[i].childNodes[0].name + nowrownum;

他们在IE8中修复了此问题。在以前的版本中,调用createElement时需要包含名称。从MSDN:

Internet Explorer 8及更高版本可以在运行时设置NAME属性 在使用IHTMLDocument2::createElement动态创建的元素上 方法。在早期版本中创建具有NAME属性的元素 在使用Internet Explorer时,包括属性及其值 IHTMLDocument2::createElement方法

以下是MSDN中的示例:

var newRadioButton = document.createElement("<INPUT TYPE='RADIO' NAME='RADIOTEST'VALUE='First Choice'>")
var newRadioButton=document.createElement(“”)

因为getAttribute和setAttribute在Internet Explorer中被破坏。.通常最好避免使用这些函数。我使用此函数
newcell.childNodes[0]。id=table.rows[2]。cells[i]。childNodes[0]。id+nowrownum;
要设置idi,请尝试
newcell.childNodes[0]。name=table.rows[2]。cells[i]。childNodes[0].name+nowrownum;
但结果是相同的名称不是更改submitName是创建的请查看此链接并按照浏览器版本使用..查看此链接..您被此功能所震撼
newcell.childNodes[0].name = table.rows[2].cells[i].childNodes[0].name + nowrownum;
var newRadioButton = document.createElement("<INPUT TYPE='RADIO' NAME='RADIOTEST'VALUE='First Choice'>")