Home  >  Article  >  Web Front-end  >  The textbox textbox changes color when the mouse passes over it_Form special effects

The textbox textbox changes color when the mouse passes over it_Form special effects

WBOY
WBOYOriginal
2016-05-16 18:52:381255browse
JS file:
Copy code The code is as follows:

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:
Copy code The code is as follows:

/*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;
}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn