DOM方法无法在Chrome,Safari,Mozilla中运行,在IE *中运行良好

时间:2013-08-12 12:38:36

标签: javascript google-chrome firefox safari

这里我的代码场景是,当用户点击添加如此动态地在表中添加了一行,因为我正在使用javascript函数.. html代码如下::

<td class="addtxt" onClick="addParameterValue('parameterFields','fieldvalue','actualdt','name','shortname','defaultvalue','secured','syncid')">Add</td>

我调用的函数如下所示::

function addParameterValue(tableid,fieldvalue,actualdt,name,shortname,defaultvalue,secured,syncid)
{

 var fieldname1=document.getElementById(fieldvalue).value;  
    var fieldValueLength =  document.getElementById(fieldvalue).maxLength;

        var tableRowsLength = document.getElementById(tableid).rows.length;
        var textBoxesLength = tableRowsLength - 6;
        var idValue = fieldvalue+1;
        benIncr=tableRowsLength;
        var flag = true;
        flag=fieldMandatory(fieldname1);
        if(flag)
        {
           var tbl = document.getElementById(tableid);
            lastRow = tbl.rows.length;
            iteration= lastRow;
            var row = tbl.insertRow(lastRow);
            row.className='detailsPageValue';

             var absence0 = row.insertCell(0);
             addTextBox(fieldvalue);
             textBoxRow.id=fieldvalue+benIncr;
             textBoxRow.maxLength="6"
             textBoxRow.onkeyup=function(){convertLowerCaseToUpperCase(this.id)}
             absence0.appendChild(textBoxRow);
             var node1= document.createTextNode(' ');
             absence0.appendChild(node1);

             var absence1 = row.insertCell(1);
             addTextBox(actualdt);
             textBoxRow.id=actualdt+benIncr;
             textBoxRow.readOnly=true;
             absence1.appendChild(textBoxRow);
             textBoxRow.className='textStyle_80';
             var node2= document.createTextNode(' ');
             absence1.appendChild(node1);
             jqueryCalender(actualdt+benIncr);

             var absence2 = row.insertCell(2);
             addTextBox(name);
             textBoxRow.id=name+benIncr;
             absence2.appendChild(textBoxRow);

             var absence3 = row.insertCell(3);
             addTextBox(shortname);
             textBoxRow.id=shortname+benIncr;
             absence3.appendChild(textBoxRow);

             var absence4 = row.insertCell(4);
             addCheckBox(defaultvalue)
             absence4.appendChild(checkBoxRow);

             var absence5 = row.insertCell(5);
              addCheckBox(secured)
             absence5.appendChild(checkBoxRow);

             var absence6 = row.insertCell(6);
             addTextBox(syncid);
             textBoxRow.id=syncid+benIncr;
             textBoxRow.onblur = function(){checkNumeric(syncid+benIncr)} 
             absence6.appendChild(textBoxRow);

             var absence7 = row.insertCell(7);
             addDeleteImage();
             absence7.appendChild(deleteImage); 


        }
        else
         {
            alert("First Row should be added");
            return false;
         }
}

根据你可以,我可以调用一个函数,它是“addText”,就像下面的::

function addTextBox(textboxid)
     {

        var txtBoxIncrement=0;
        var textLength=document.getElementById(textboxid).maxLength;
        var textSize=document.getElementById(textboxid).size;
        var textClass=document.getElementById(textboxid).className;
        textBoxRow=document.createElement('input');
        textBoxRow.type='text';
        textBoxRow.name=textboxid;
        //textBoxRow.maxLength=textLength;
        textBoxRow.size=textSize;
        textBoxRow.id=textboxid+txtBoxIncrement+'';
        txtBoxIncrement++;
        textBoxRow.className=textClass;
     }

现在主要的事情来了......在这里我调用的是.maxLength,.size和.className ......这些方法在IE *中工作正常但不适用于chrome,safari,mozilla firefox .. < / p>

伙计们帮助我...提前谢谢...... :)。

1 个答案:

答案 0 :(得分:0)

尝试使用getAttribute

document.getElementById(textboxid).getAttribute("maxlength")