Visualizzazione dei risultati da 1 a 3 su 3
  1. #1

    InsertBefore dubbio .........

    Ciao.
    Usando
    node.insertBefore(nodo_inserito,nodo_esistente)
    nodo_esistente viene sostituito da nodo_inserito
    o
    nodo_inserito si aggiunge ai childs di node

    Mi risultava che per 'salvare' nodo_esistente
    si dovesse usare node.cloneNode(nodo_esistente)
    ma da questo snippet non sembrerebbe:

    Codice PHP:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <
    html xmlns="http://www.w3.org/1999/xhtml">
    <
    head>
    <
    title>Untitled Document</title>
    <
    meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <
    style type="text/css">
    * {
        
    margin:0px;
        
    padding:0px
    }
    body 
        
    text-align:center
    }
    div#container {
        
    margin0px auto;
        
    width:700px;
        
    border1px solid #CCCCCC;
        
    text-align:left;
    }
    div#header { 
        
    height:80px;  
    }
    div#target{ 
        
    margin:30pxwidth:200pxbackground-color:#FFFFCC;
    }
    </
    style>
    <
    script language="javascript" type="text/javascript">
    function 
    addEvent(elmevTypefnuseCapture){
        if (
    elm.addEventListener){
                
    elm.addEventListener(evTypefnuseCapture);
                return 
    true;
        } else if (
    elm.attachEvent) {
            var 
    elm.attachEvent('on' evTypefn);
            return 
    r;
        } else {
            
    elm['on' evType] = fn;
        }
    };
    function $(){
        var 
    elements = new Array();
        for (var 
    0;i<arguments.length;i++){
            var 
    element arguments[i];
            if (
    typeof element == 'string'){
              
    element document.getElementById(element);
            }
            if (
    arguments.length == 1){
              return 
    element;
            }
            
    elements.push(element);
          }
        return 
    elements;
    };
    function 
    _createElement(el){
        return 
    document.createElement(el);
    }
    function 
    _createTextNode(text){
        return 
    document.createTextNode(text);
    }

    function 
    addCategory(){
        var 
    idString'category-';
        var 
    categoryList= $('categoryList');
        var 
    countcategoryList.getElementsByTagName('li').length;
        var 
    current= $(idString+count);
        
    alert(current.getAttribute('id'));
        var 
    catInputValue= $('catInputField').value;
        var 
    catValue_createTextNode(catInputValue);
        var 
    li_createElement('li');
        
    count++;
        
    li.setAttribute('id',idString+count);
        
    li.appendChild(catValue);
        
    alert(li.getAttribute('id'));
        
    categoryList.insertBefore(li,current);
    }
    function 
    init(){
        var 
    catInsertButton= $('catInsertButton');
        
    addEvent(catInsertButton,'click',addCategory,false);
    }
    addEvent(window,'load',init,false);
    </script>

    </head>

    <body>
    <div id="container">
    <div id="header"><h1>Test</h1></div>
        <div id="target">
        <p id="jaxcat">
            <input id="catInputField" name="cat" type="text" maxlength="30" />
            <input id="catInsertButton" name="insert" type="button" value="_go_!" />
        </p>
            <ul id="categoryList">
                <li id="category-1">Uno
            [/list]
        </div>
    </div>
    </body>
    </html> 


    Without faith, nothing is possible. With it, nothing is impossible
    http://ilwebdifabio.it

  2. #2
    Utente di HTML.it L'avatar di andbin
    Registrato dal
    Jan 2006
    residenza
    Italy
    Messaggi
    18,284

    Re: InsertBefore dubbio .........

    Originariamente inviato da whisher
    Ciao.
    Usando
    node.insertBefore(nodo_inserito,nodo_esistente)
    nodo_esistente viene sostituito da nodo_inserito
    o
    nodo_inserito si aggiunge ai childs di node
    La seconda che hai detto.

    parentElement.insertBefore(newElement, referenceElement)

    newElement viene aggiunto come figlio di parentElement, posizionandolo prima di referenceElement.
    Andrea, andbin.devSenior Java developerSCJP 5 (91%) • SCWCD 5 (94%)
    java.util.function Interfaces Cheat SheetJava Versions Cheat Sheet

  3. #3
    Without faith, nothing is possible. With it, nothing is impossible
    http://ilwebdifabio.it

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.