JS file:
function mouseAction( ) {
var textInputs = document.getElementsByTagName("input");
var len = textInputs.length;
var index = 0;
var textInput;
/*
also You can use the for in statement to traverse
for (textInput in textInputs){
textInputs[textInput].onmouseover = functionName;
}
*/
for( index = 0; index < len ; index ) {
textInput = textInputs[index];
if( textInput.getAttribute("type") == "text" ){
textInput.onmouseover = function (){
// You can also use this method this.style.backgroundColor = "red";
this.className = "txtMouseOver"; //Introduce the CSS file into the HTML first
}; //Be sure to add a semicolon
textInput.onmouseout = function(){
this.className = "txtMouseOut";
};
textInput.onfocus = function(){
this.className = "txtMouseFocus";
};
textInput.onblur = function(){
this.className = "txtMouseBlur";
};
}
}
}
//You can also directly follow a function name without quotation marks, brackets window.onload = mouseAction;
window.onload = function(){
mouseAction();
} ;
CSS file:
/*The body is displayed in the center*/
body{
width: 80%;
height: 800px;
position: relative;
margin-left: 10% ;
/*left: -40%;*/
border: #00CCFF solid thin;
}
.txtMouseOver
{
border-color: #9ecc00;
}
.txtMouseOut
{
border-color: #84a1bd;
}
.txtMouseFocus
{
border-color: #9ecc00;
background-color: #e8f9ff;
}
.txtMouseBlur
{
border-color: #84a1bd;
background-color: #ffffff;
}