ТД работает по центру и по левому краю, но не по правому краю - PullRequest
0 голосов
/ 01 июня 2011

Мой код добавляет одну строку таблицы динамически. Выравнивание работает для первого ряда, который является статическим, но не для других рядов. В связи с этим я проверил динамическое содержимое с атрибутом выравнивания по центру, и оно работает.

Вот часть кода, которую я обновляю, и ниже полной функции.

colsfila=document.createElement('td');
textonodo=document.createTextNode(qTrib);
idnodo='qTrib'+NUM_FILAS;
colsfila.setAttribute('id', idnodo);
colsfila.setAttribute('onclick','addInputdetCompra(this)');
colsfila.setAttribute('style', 'text-align: center;');
colsfila.appendChild(textonodo);
novafila.appendChild(colsfila);

colsfila=document.createElement('td');
textonodo=document.createTextNode(vUnTrib);
idnodo='vUnTrib'+NUM_FILAS;
var align='rigth';
colsfila.setAttribute('id', idnodo);
colsfila.setAttribute('onclick','addInputdetCompra(this)');
colsfila.appendChild(textonodo);
colsfila.setAttribute('style','text-align :rigth;');
novafila.appendChild(colsfila);

function importxmlcompra(){
    var novostring= new String(document.getElementById('file').value);

    if (novostring!=''){
        oPed.open("GET",novostring, false);
        oPed.send();
        var result = oPed.responseXML;
        if (!result.documentElement && oPed.responseStream) {
        result.load(oPed.responseStream);
        }   
    }else{
            alert ("Por favor seleccione un arquivo XML");
    }
    if (!result||result.getElementsByTagName('emit').length==0){
        return};
    var emit=result.getElementsByTagName("emit")[0];
    var dEmi=result.getElementsByTagName('dEmi')[0].childNodes[0].nodeValue;
    dEmi=dataNF(dEmi);
    document.getElementById('dEmi').value=dEmi;
    var CNPJ=emit.getElementsByTagName('CNPJ')[0].childNodes[0].nodeValue;
    document.getElementById('cnpj').value=CNPJ;
    var razaosocialimportada=emit.getElementsByTagName("xNome")[0].childNodes[0].nodeValue;
    document.getElementById("xNome").value=razaosocialimportada;
    var ide=result.getElementsByTagName("ide")[0];
    var nNF=ide.getElementsByTagName("nNF")[0].childNodes[0].nodeValue;
    document.getElementById("nNF").value=nNF;
    var vNF='R$'+number_format(result.getElementsByTagName("vNF")[0].childNodes[0].nodeValue,2,',','.');
    document.getElementById("vNF").value=vNF;

    var detlength=result.getElementsByTagName("det").length;
    var j=0, cProd, xProd, vUnTrib, qTrib, vProd;
    var tabledet=document.getElementsByTagName('table')[0];
    var tablerows=document.getElementsByTagName('table')[0].rows.length;
    var novafila, colsfila, idnodo, textonodo, imgnodo, attid, ant;

    while(j<detlength){
        det=result.getElementsByTagName('det')[j];
        cProd=det.getElementsByTagName('cProd')[0].childNodes[0].nodeValue;
        xProd=det.getElementsByTagName('xProd')[0].childNodes[0].nodeValue;
        vUnTrib=number_format(det.getElementsByTagName('vUnTrib')[0].childNodes[0].nodeValue,2,',','.');
        qTrib=number_format(det.getElementsByTagName('qTrib')[0].childNodes[0].nodeValue,0,'','.');
        vProd=number_format(det.getElementsByTagName('vProd')[0].childNodes[0].nodeValue,2,',','.');


        if(validacProd(cProd)==true){

            if (tablerows==2&& document.getElementById('cProd0').innerHTML=='0'){
              document.getElementById('cProd0').innerHTML=cProd;
              document.getElementById('xProd0').innerHTML=xProd;
              document.getElementById('vUnTrib0').innerHTML=vUnTrib;
              document.getElementById('qTrib0').innerHTML=qTrib;
              document.getElementById('vProd0').innerHTML=vProd;
            }else{
                novafila=document.createElement('tr');
                textonodo=document.createTextNode(cProd);
                attid=document.createAttribute('id');
                colsfila=document.createElement('td');
                idnodo='cProd'+NUM_FILAS;
                colsfila.setAttribute('id', idnodo);
                colsfila.setAttribute('onclick','addInputdetCompra(this)');
                colsfila.appendChild(textonodo);
                novafila.appendChild(colsfila);
                tabledet.appendChild(novafila)

                colsfila=document.createElement('td');
                textonodo=document.createTextNode(xProd);
                idnodo='xProd'+NUM_FILAS;
                colsfila.setAttribute('id', idnodo);
                colsfila.setAttribute('onclick','addInputdetCompra(this)');
                colsfila.appendChild(textonodo);
                novafila.appendChild(colsfila);

                colsfila=document.createElement('td');
                idnodo='codproduto'+NUM_FILAS;
                colsfila.setAttribute('id', idnodo);
                colsfila.setAttribute('style','display:none');
                novafila.appendChild(colsfila);

                colsfila=document.createElement('td');
                idnodo='descproduto'+NUM_FILAS;
                colsfila.setAttribute('id', idnodo);
                colsfila.setAttribute('onclick','addInputdetCompra(this)');
                novafila.appendChild(colsfila);

                colsfila=document.createElement('td');
                textonodo=document.createTextNode(qTrib);
                idnodo='qTrib'+NUM_FILAS;
                colsfila.setAttribute('id', idnodo);
                colsfila.setAttribute('onclick','addInputdetCompra(this)');
                colsfila.setAttribute('style', 'text-align: center;');
                colsfila.appendChild(textonodo);
                novafila.appendChild(colsfila);

                colsfila=document.createElement('td');
                textonodo=document.createTextNode(vUnTrib);
                idnodo='vUnTrib'+NUM_FILAS;
                var align='rigth';
                colsfila.setAttribute('id', idnodo);
                colsfila.setAttribute('onclick','addInputdetCompra(this)');
                colsfila.appendChild(textonodo);
                colsfila.setAttribute('style','text-align :rigth;');
                novafila.appendChild(colsfila);

                colsfila=document.createElement('td');
                textonodo=document.createTextNode(vProd);
                idnodo='vProd'+NUM_FILAS;
                colsfila.setAttribute('id', idnodo);
                colsfila.setAttribute('align', 'rigth');
                colsfila.appendChild(textonodo);
                novafila.appendChild(colsfila);

                colsfila=document.createElement('td');
                imgnodo=document.createElement('img');
                idnodo='addrow'+NUM_FILAS;
                colsfila.setAttribute('id', idnodo);
                colsfila.setAttribute('onclick','addRowdetCompra(this)');
                imgnodo.setAttribute('src','../../../imagens/addrow/addrow.png');
                colsfila.appendChild(imgnodo);
                novafila.appendChild(colsfila);
                document.getElementsByTagName('table')[0].appendChild(novafila);
            }
        }
        tablerows=document.getElementsByTagName('table')[0].rows.length;
        NUM_FILAS++;
        j++;
    }
    comandosfilas();
}

Ответы [ 2 ]

0 голосов
/ 02 июня 2011

Вы пишете правильно неправильно в нескольких местах. Выполните поиск и замените rigth на right.

0 голосов
/ 01 июня 2011

Опечатка:

colsfila.setAttribute('style','text-align :rigth;');
                                           ^^^^^ - should be 'right'

Если вы откроете консоль ошибок вашего браузера (например, shift-ctrl-J в Firefox), вы увидите сообщение об ошибке.

...