Home > Web Front-end > JS Tutorial > body text

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

WBOY
Release: 2016-05-16 18:52:38
Original
1256 people have browsed it
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;
}
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template