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

    Semplice script non funziona in IE :(

    Ciao.
    Ho questo semplice script:
    Codice PHP:
    <html>
    <
    head><title>DOM equals greatness</title>
    <
    script type="text/javascript">
    function 
    displayInfo(whatinfo){
    var 
    info document.createElement("p");
    document.body.appendChild(info);
    switch(
    whatinfo){
    case 
    "attributes":
    var 
    text "You have getAttribute and setAttribute. getAttribute takes one argument, setAttribute takes two.";
    break;
    case 
    "tree":
    var 
    text "There are two functions: getElementsByTagName, which returns an array, and getElementById, which returns a single element based on the id attribute.";
    break;
    case 
    "god":
    var 
    text "There are many functions. createElement, appendChild, insertBefore, createTextNode, and removeChild.";
    break;
    }
    info.innerHTML text;
    }
    </script></head><body>
    <form action="formaction" method="post">
    Methods in the DOM: <select name="selection">
    <option value="attributes" onclick="displayInfo(this.value)">Attributes</option>
    <option value="tree" onclick="displayInfo(this.value)">Traversing the Tree</option>
    <option value="god" onclick="displayInfo(this.value)">Creating and destroying nodes</option>
    </select>
    </form>
    </body></html> 
    In FF funziona in IE no e non so spiegarmi perchè
    c'è qc che me lo spiega
    Mi piacerebbe sapere come fare per togliere
    quel orribile onclick sulle options usando js
    non intrusivo qc suggerimento

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

  2. #2
    Utente di HTML.it L'avatar di Xinod
    Registrato dal
    Sep 2000
    Messaggi
    13,649
    <select name="selection" onchange="displayInfo(this.options[this.selectedIndex].value)">
    e almeno ti liberi di quell' aberrazione di onclick sulle option

    se poi vuoi farlo completamente non intrusivo il discorso si complica un po'
    niente di trascendentale ma ora

  3. #3

    ...............

    Ciao.
    Ti ringranzio molto per l'interessamento
    ma la tua modifica non funziona anche se il
    codice sembrerebbe a posto.
    Ci litigo un po e poi ti faccio sapere.
    Certo che lo vorrei trasformare in js
    non intrusivo.
    Ah mi piacerebbe anche capire xchè
    con IE non funziona.


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

  4. #4

    ..........

    Oh versione Unobtrusive Javascript e penso
    cross-browser :
    Codice PHP:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd"
    >
    <
    html>
    <
    head>
    <
    title>Untitled Document</title>
    <
    meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <
    script language="JavaScript" type="text/JavaScript">
    function 
    DOMize(element
    {
        if(!
    element.addEventListener)
        {
            
    element.addEventListener=function(event,listener)
                                    {
                                        
    event="on"+event;
                                        if(
    this.attachEvent)
                                        {    
                                            
    this.attachEvent(event,listener);
                                        }
                                        else 
                                        {            
                                            
    this[event]=listener;
                                        }
                                     }

        };
        if(!
    element.removeEventListener)
        {
            
    element.removeEventListener=function(event,listener)
                                        {
                                            
    event="on"+event;
                                            if(
    this.detachEvent)    
                                            {
                                                
    this.detachEvent(event,listener);
                                            }
                                            else     
                                            {        
                                                    
    delete this[event];
                                            }
                                        }
        };
        return 
    element;
    };
    function 
    displayInfo()
    {
    var 
    sel document.getElementsByTagName("select")[0];
    var 
    whatinfo sel.options[sel.selectedIndex].value;
    if(
    test document.getElementById("paragraph")) {
    document.body.removeChild(test);
    }
    var 
    info document.createElement("p");
    info.setAttribute("id""paragraph");
    switch(
    whatinfo){
    case 
    "attributes":
    var 
    text document.createTextNode("You have getAttribute and setAttribute. getAttribute takes one argument, setAttribute takes two.");
    break;
    case 
    "tree":
    var 
    text document.createTextNode("There are two functions: getElementsByTagName, which returns an array, and getElementById, which returns a single element based on the id attribute.");
    break;
    case 
    "god":
    var 
    text document.createTextNode("There are many functions. createElement, appendChild, insertBefore, createTextNode, and removeChild.");
    break;
    }
    info.appendChild(text);
    document.body.appendChild(info);

    }
    window.onload = function()
    {
    var 
    sel document.getElementsByTagName("select")[0];
    DOMize(sel).addEventListener("change",displayInfofalse); 
    }
    </script>


    </head>

    <body>
    <form action="formaction" method="post">
    Methods in the DOM: 
    <select name="selection">
    <option value="attributes">Attributes</option>
    <option value="tree">Traversing the Tree</option>
    <option value="god">ting and destroying nodes</option>
    </select>
    </form> 
    </body>
    </html> 
    un grazie ad andr3a per la function DOMize.
    Ulteriori migliorie sono ben accette.
    Sappimi dire.





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

  5. #5

    ........

    Un minimo + flessibile con l'aggiunta di un target:
    Codice PHP:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd"
    >
    <
    html>
    <
    head>
    <
    title>Untitled Document</title>
    <
    meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <
    script language="JavaScript" type="text/JavaScript">
    function 
    DOMize(element
    {
        if(!
    element.addEventListener)
        {
            
    element.addEventListener=function(event,listener)
                                    {
                                        
    event="on"+event;
                                        if(
    this.attachEvent)
                                        {    
                                            
    this.attachEvent(event,listener);
                                        }
                                        else 
                                        {            
                                            
    this[event]=listener;
                                        }
                                     }

        };
        if(!
    element.removeEventListener)
        {
            
    element.removeEventListener=function(event,listener)
                                        {
                                            
    event="on"+event;
                                            if(
    this.detachEvent)    
                                            {
                                                
    this.detachEvent(event,listener);
                                            }
                                            else     
                                            {        
                                                    
    delete this[event];
                                            }
                                        }
        };
        return 
    element;
    };
    function 
    displayInfo()
    {
    var 
    sel document.getElementsByTagName("select")[0];
    var 
    whatinfo sel.options[sel.selectedIndex].value;
    if(
    test document.getElementById("paragraph")) {
    document.getElementById("target").removeChild(test);
    }
    var 
    info document.createElement("p");
    info.setAttribute("id""paragraph");
    switch(
    whatinfo){
    case 
    "attributes":
    var 
    text document.createTextNode("You have getAttribute and setAttribute. getAttribute takes one argument, setAttribute takes two.");
    break;
    case 
    "tree":
    var 
    text document.createTextNode("There are two functions: getElementsByTagName, which returns an array, and getElementById, which returns a single element based on the id attribute.");
    break;
    case 
    "god":
    var 
    text document.createTextNode("There are many functions. createElement, appendChild, insertBefore, createTextNode, and removeChild.");
    break;
    }
    info.appendChild(text);
    document.getElementById("target").appendChild(info);

    }
    window.onload = function()
    {
    var 
    sel document.getElementsByTagName("select")[0];
    DOMize(sel).addEventListener("change",displayInfofalse); 
    }
    </script>


    </head>

    <body>
    <form action="formaction" method="post">
    Methods in the DOM: 
    <select name="selection">
    <option value="attributes">Attributes</option>
    <option value="tree">Traversing the Tree</option>
    <option value="god">ting and destroying nodes</option>
    </select>
    </form> 
    <div id="target"></div>
    </body>
    </html> 
    Without faith, nothing is possible. With it, nothing is impossible
    http://ilwebdifabio.it

  6. #6

    ...........

    E finalmente Ajax:
    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>
    <
    meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <
    title>Our wonderful AJAX page!</title>
    <
    script language="javascript" type="text/javascript">
    function 
    DOMize(element
    {
        if(!
    element.addEventListener)
        {
            
    element.addEventListener=function(event,listener)
                                    {
                                        
    event="on"+event;
                                        if(
    this.attachEvent)
                                        {    
                                            
    this.attachEvent(event,listener);
                                        }
                                        else 
                                        {            
                                            
    this[event]=listener;
                                        }
                                     }

        };
        if(!
    element.removeEventListener)
        {
            
    element.removeEventListener=function(event,listener)
                                        {
                                            
    event="on"+event;
                                            if(
    this.detachEvent)    
                                            {
                                                
    this.detachEvent(event,listener);
                                            }
                                            else     
                                            {        
                                                    
    delete this[event];
                                            }
                                        }
        };
        return 
    element;
    };
    function 
    getPage(){

    var 
    xmlhttp=false//Clear our fetching variable
            
    try {
                    
    xmlhttp = new ActiveXObject('Msxml2.XMLHTTP'); //Try the first kind of active x object…
            
    } catch (e) {
                    try {
                            
    xmlhttp = new
                            
    ActiveXObject('Microsoft.XMLHTTP'); //Try the second kind of active x object
                
    } catch (e) {
                    
    xmlhttp false;
                            }
            }
            if (!
    xmlhttp && typeof XMLHttpRequest!='undefined') {
                    
    xmlhttp = new XMLHttpRequest(); //If we were able to get a working active x object, start an XMLHttpRequest
            
    }
            var 
    file 'query.php?page=';
             
    //This is the path to the file we just finished making *
            
    var sel document.getElementsByTagName("select")[0];
            var 
    whatinfo sel.options[sel.selectedIndex].value;
            
    xmlhttp.open('GET'file whatinfotrue); //Open the file through GET, and add the page we want to retrieve as a GET variable **
            
    xmlhttp.onreadystatechange=function() {
            if (
    xmlhttp.readyState==4) { //Check if it is ready to recieve data
                    
    var content xmlhttp.responseText//The content data which has been retrieved ***
                    
    if( content ){ //Make sure there is something in the content variable

                
    if(test document.getElementById("paragraph")) {
                
    document.getElementById("target").removeChild(test);
                }
                    var 
    info document.createElement("p");
                    
    info.setAttribute("id""paragraph");
                    var 
    text document.createTextNode(content);
                    
    info.appendChild(text);
                    
    document.getElementById("target").appendChild(info);
                }
            }
            }
            
    xmlhttp.send(null//Nullify the XMLHttpRequest
    return;
    }
    window.onload = function()
    {
    var 
    sel document.getElementsByTagName("select")[0];
    DOMize(sel).addEventListener("change",getPagefalse); 
    }

    </script>
    </head>
    <body>
    <form method="get">
    <select name="choosepage">
    <option  value="">Choose page</option>
    <option  value="uno">Page One</option>
    <option value="due">Page Two</option>
    </select>
    </form>
    <div id="target"></div>
    </body>
    </html> 
    Mi sembra che inizi ad essere decente come implementazione
    come si dice da cosa nasce cosa basta iniziare .......
    un pezzetto di quà un'altro di là


    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.