鼠標(biāo)經(jīng)過的文本框textbox變色
更新時(shí)間:2009年05月21日 18:42:50 作者:
文本框 textbox 變色
JS文件:
function mouseAction() {
var textInputs = document.getElementsByTagName("input");
var len = textInputs.length;
var index = 0;
var textInput;
/*
也能用 for in 語(yǔ)句遍歷
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 (){
//也能用這種方式 this.style.backgroundColor = "red";
this.className = "txtMouseOver"; //要先在HTML中引入CSS文件
}; //注意要加分號(hào)
textInput.onmouseout = function(){
this.className = "txtMouseOut";
};
textInput.onfocus = function(){
this.className = "txtMouseFocus";
};
textInput.onblur = function(){
this.className = "txtMouseBlur";
};
}
}
}
//也可以直接跟一個(gè)函數(shù)名,不要加引號(hào),括號(hào) window.onload = mouseAction;
window.onload = function(){
mouseAction();
};
CSS文件:
/*主體居中顯示*/
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;
}
復(fù)制代碼 代碼如下:
function mouseAction() {
var textInputs = document.getElementsByTagName("input");
var len = textInputs.length;
var index = 0;
var textInput;
/*
也能用 for in 語(yǔ)句遍歷
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 (){
//也能用這種方式 this.style.backgroundColor = "red";
this.className = "txtMouseOver"; //要先在HTML中引入CSS文件
}; //注意要加分號(hào)
textInput.onmouseout = function(){
this.className = "txtMouseOut";
};
textInput.onfocus = function(){
this.className = "txtMouseFocus";
};
textInput.onblur = function(){
this.className = "txtMouseBlur";
};
}
}
}
//也可以直接跟一個(gè)函數(shù)名,不要加引號(hào),括號(hào) window.onload = mouseAction;
window.onload = function(){
mouseAction();
};
CSS文件:
復(fù)制代碼 代碼如下:
/*主體居中顯示*/
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;
}
相關(guān)文章
一直復(fù)略了的一個(gè)問題,關(guān)于表單重復(fù)提交
一直復(fù)略了的一個(gè)問題,關(guān)于表單重復(fù)提交...2007-02-02
兼容Firefox和IE的onpropertychange事件oninput
onpropertychange能夠捕獲每次輸入值的變化。例如:對(duì)象的value值被改變時(shí),onpropertychange能夠捕獲每次改變,而onchange需要執(zhí)行某個(gè)事件才可以捕獲。2008-06-06

