Visualizzazione dei risultati da 1 a 5 su 5

Discussione: creare tabella con DOM

  1. #1
    Utente di HTML.it L'avatar di agenti
    Registrato dal
    Feb 2002
    Messaggi
    2,427

    creare tabella con DOM

    Scusate ragazzi sono che non si fa ma... non ho il tempo di leggere il Dom... così hotrovato questo esempio molto chiaro tra l'altro.

    <script>
    function start() {
    // get the reference for the body
    var mybody=document.getElementsByTagName("body").item( 0);
    // creates an element whose tag name is TABLE
    mytable = document.createElement("TABLE");
    // creates an element whose tag name is TBODY
    mytablebody = document.createElement("TBODY");
    // creating all cells
    for(j=0;j<1;j++) {
    // creates an element whose tag name is TR
    mycurrent_row=document.createElement("TR");
    // creates an element whose tag name is TD
    mycurrent_cell=document.createElement("TD");
    mycurrent_cell1=document.createElement("TD");
    // creates a Text Node
    currenttext=document.createTextNode('<input type\'text\'>');
    currenttext1=document.createTextNode("ok2");
    // appends the Text Node we created into the cell TD
    mycurrent_cell.appendChild(currenttext);
    mycurrent_cell1.appendChild(currenttext1);
    // appends the cell TD into the row TR
    mycurrent_row.appendChild(mycurrent_cell);
    mycurrent_row.appendChild(mycurrent_cell1);
    // appends the row TR into TBODY
    mytablebody.appendChild(mycurrent_row);
    }
    // appends TBODY into TABLE
    mytable.appendChild(mytablebody);
    // appends TABLE into BODY
    mybody.appendChild(mytable);
    // sets the border attribute of mytable to 2;
    mytable.setAttribute("border","2");
    }
    </script>


    funziona correttamente solo che ho un limite nella creazione di html all'interno del TD

    currenttext=document.createTextNode ('<input type\'text\'>')

    visualizza in realtà il testo per comè non come html....

    in realtà è chiaro che volgio inserire un campo input text

    come posso fare.
    Grazie.

  2. #2
    Utente di HTML.it L'avatar di Xinod
    Registrato dal
    Sep 2000
    Messaggi
    13,649
    almeno l' esempio che stai usando studialo

    un <input> e' come un <td>, un elemento, quindi
    - crealo con createElement
    var inp=document.createElement("INPUT");
    - inp.setAttribute('type','text')
    - mycurrent_cell.appendChild('inp')

    ciao

  3. #3
    Utente di HTML.it L'avatar di agenti
    Registrato dal
    Feb 2002
    Messaggi
    2,427
    fatto...

    ma...
    creo l'input...
    provo a mandare un parametro e a riceverlo...
    non ricevo nulla



    <form action="table_dom.asp">
    <script>
    function start() {
    // get the reference for the body
    var mybody=document.getElementsByTagName("body").item( 0);
    // creates an element whose tag name is TABLE
    mytable = document.createElement("TABLE");
    // creates an element whose tag name is TBODY
    mytablebody = document.createElement("TBODY");
    // creating all cells
    for(j=0;j<1;j++) {
    // creates an element whose tag name is TR
    mycurrent_row=document.createElement("TR");
    // creates an element whose tag name is TD
    mycurrent_cell=document.createElement("TD");
    mycurrent_cell1=document.createElement("TD");
    inp=document.createElement("INPUT")
    // creates a Text Node
    inp.setAttribute('type','text')
    inp.setAttribute('name','campo1')
    inp.setAttribute('value','campo1')
    // appends the Text Node we created into the cell TD
    mycurrent_cell.appendChild(inp)
    // appends the cell TD into the row TR
    mycurrent_row.appendChild(mycurrent_cell);
    // appends the row TR into TBODY
    mytablebody.appendChild(mycurrent_row);
    }
    // appends TBODY into TABLE
    mytable.appendChild(mytablebody);
    // appends TABLE into BODY
    mybody.appendChild(mytable);
    // sets the border attribute of mytable to 2;
    mytable.setAttribute("border","1");
    }
    </script>



    ddd</p>


    <input type="submit" value="Invia" name="B1"></p>

    </form>

    <%
    if request("campo1")<> "" then
    response.write "test"
    %>
    <%end if%>

  4. #4
    Utente di HTML.it L'avatar di Xinod
    Registrato dal
    Sep 2000
    Messaggi
    13,649
    sbaglio o appendi tutto al body?
    (quindi fuori dal <form>)

  5. #5
    Utente di HTML.it L'avatar di agenti
    Registrato dal
    Feb 2002
    Messaggi
    2,427
    manca l'icona con il martello sulla capa....

    beh sarebbe adatta a me adesso!


Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.