2010-05-13 68 views

回答

18

JavaScript验证不安全,因为任何人都可以更改您的脚本在浏览器中的功能。不过,使用它来增强视觉体验是可以的。

var textBox = document.getElementById("myTextBox"); 
var textLength = textBox.value.length; 
if(textLength > 5) 
{ 
    //red 
    textBox.style.backgroundColor = "#FF0000"; 
} 
else 
{ 
    //green 
    textBox.style.backgroundColor = "#00FF00"; 
}