Visualizzazione dei risultati da 1 a 2 su 2

Discussione: problema con array

  1. #1

    problema con array

    ripreso in mano js dopo due anni... ho un problema col seguente codice:

    codice:
    var propsList = new Array(
    	   "azimuth", 
    	   "background-attachment",
    	   "background-color",
    	   "background-image",
    	   "background-position",
    	   "background-repeat",
    	   "background",
    	   "border-collapse",
    	   "border-color",
    	   "border-spacing",
    	   "border-style",
    	   "border-top",
    	   "border-right",
    	   "border-bottom",
    	   "border-left",
    	   "border-top-color",
    	   "border-right-color",
    	   "border-bottom-color",
    	   "border-left-color",
    	   "border-top-style",
    	   "border-right-style",
    	   "border-bottom-style",
    	   "border-left-style",
    	   "border-top-width",
    	   "border-right-width",
    	   "border-bottom-width",
    	   "border-left-width",
    	   "border-width",
    	   "border",
    	   "bottom",
    	   "caption-side",
    	   "clear",
    	   "clip",
    	   "color",
    	   "content",
    	   "counter-increment",
    	   "counter-reset",
    	   "cue-after",
    	   "cue-before",
    	   "cue",
    	  "cursor",
    	   "direction",
    	   "display",
    	  "elevation",
    	   "empty-cells",
    	  "float",
    	  "font-family",
    	   "font-size",
    	   "font-style",
    	  "font-variant",
    	   "font-weight",
    	   "font",
    	   "height",
    	   "left",
    	   "letter-spacing",
    	  "line-height",
    	   "list-style-image",
    	  "list-style-position",
    	  "list-style-type",
    	   "list-style",
    	   "margin-left",
    	   "margin-right",
    	   "margin-top",
    	   "margin-bottom",
    	   "margin",
    	   "max-height",
    	   "max-width",
    	   "min-height",
    	   "min-width",
    	   "orphans",
    	   "outline-color",
    	   "outline-style",
    	   "outline-width",
    	   "outline",
    	   "overflow",
    	   "padding-top",
    	   "padding-right",
    	   "padding-bottom",
    	   "padding-left",
    	   "padding",
    	   "page-break-after",
    	   "page-break-before",
    	   "page-break-inside",
    	   "pause-after",
    	   "pause-before",
    	   "pause",
    	   "pitch-range",
    	   "pitch",
    	   "play-during",
    	   "position",
    	   "quotes",
    	  "richness",
    	   "right",
    	   "speak-header",
    	   "speak-numeral",
    	   "speak-punctuation",
    	   "speak",
    	   "speech-rate",
    	   "stress",
    	   "table-layout", 
    	   "text-align",
    	   "text-decoration",
    	   "text-indent",
    	   "text-transform",
    	   "top",
    	   "unicode-bidi",
    	   "vertical-align",
    	   "visibility",
    	   "voice-family",
    	   "volume",
    	   "white-space",
    	   "widows",
    	   "width",
    	   "word-spacing",
    	   "z-index");
    	   
    
    
    function showBadResult() {
             var badresult = document.getElementById("test");
    	 var msg = document.createTextNode("This is not a valid CSS 2.1 property.");
    	 var newelem = document.createElement("p");
    	 newelem.appendChild(msg);
    	 newelem.style.margin = "0.5em";
    	 newelem.style.padding = "1em";
    	 newelem.style.border = "1px solid red";
    	 newelem.style.backgroundColor = "#ffc";
    	 newelem.style.fontFamily = "Arial, sans-serif";
    	 newelem.style.fontWeight = "bold";
    	 newelem.style.color = "#c00";
    	 badresult.appendChild(newelem);
    	 
    	 
    }
    
    
    function showGoodResult() {
            var goodresult = document.getElementById("test");
    	var gmsg = document.createTextNode("This is a valid CSS 2.1 property.");
            var newelem2 = document.createElement("p");
            newelem2.appendChild(gmsg);
    	
             newelem2.style.margin = "0.5em";
    	 newelem2.style.padding = "1em";
    	 newelem2.style.border = "1px solid green";
    	 newelem2.style.backgroundColor = "#c0ffc0";
    	 newelem2.style.fontFamily = "Arial, sans-serif";
    	 newelem2.style.fontWeight = "bold";
    	 newelem2.style.color = "green";
    	 goodresult.appendChild(newelem2);
    
    }
    
    function checkProps() {
               
    	   var testo = document.getElementById("test").text.value.toLowerCase();
    	   
    	   
    	   for (var i=0; i<propsList.length; i++) {
    	   
    	   if (testo == propsList[i]) {
    	     
    	     showGoodResult()
    	  
    	   }
    	   
    	   else if (testo != propsList[i]) {
    	   showBadResult()
    	   }
    	  
    	break;
    	   }
    	   
    	   
    	   
    }
    in pratica la verifica si blocca al primo indice dell'array e da risultato negativo
    per tutti gli altri indici. suggerimenti? perdonate il js-spaghetti e l'ignoranza. ciao

  2. #2
    Frontend samurai L'avatar di fcaldera
    Registrato dal
    Feb 2003
    Messaggi
    12,924
    togli il break; finale


    e document.getElementById("test").text.value.toLower Case()
    dovrebbe essere invece document.getElementById("test").innerHTML.toLowerC ase()
    Vuoi aiutare la riforestazione responsabile?

    Iscriviti a Ecologi e inizia a rimuovere la tua impronta ecologica (30 alberi extra usando il referral)

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.