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

    confrontare due variabili trimmate....

    <html>

    <head>
    <script>
    function trim(item)
    {
    worker = new String(item);

    if (worker.indexOf(" ") != -1)
    {
    if (worker.indexOf(" ") == 0)
    {
    worker = worker.substring(1,worker.length);
    trim(worker);
    }
    }
    if (worker.lastIndexOf(" ") != -1)
    {
    if (worker.lastIndexOf(" ") >= worker.length-1)
    {
    worker = worker.substring(0,worker.length-1);
    trim(worker);
    }
    }

    return worker;
    }
    </script>
    </head>

    <body>
    <script>
    var x="AQ";
    var y="AQ";
    x=trim(x);
    y=trim(y);
    alert(x == y);
    </script>

    </body>

    </html>

    l'alert mi restituisce false..............

  2. #2
    Utente di HTML.it L'avatar di badaze
    Registrato dal
    Jun 2002
    residenza
    Lyon
    Messaggi
    5,359
    Forse cosi....
    codice:
    <html> 
    
    <head> 
    <script> 
    function ltrim(item) { 
    return item.replace(/^\s*/gi,""); 
    } 
    function rtrim(item) { 
    return item.replace(/\s*$/gi,""); 
    } 
    function trim(item) {
     a = ltrim(item);
     return rtrim(a);
    }
    </script> 
    </head> 
    
    <body> 
    <script> 
    var x="        AQ "; 
    var y=" AQ          "; 
    x=trim(x); 
    y=trim(y); 
    alert(x == y); 
    </script> 
    
    </body> 
    
    </html>

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 © 2024 vBulletin Solutions, Inc. All rights reserved.