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