手机
当前位置:查字典教程网 >编程开发 >Javascript教程 >鼠标经过的文本框textbox变色
鼠标经过的文本框textbox变色
摘要:JS文件:复制代码代码如下:functionmouseAction(){vartextInputs=document.getElements...

JS文件:

复制代码 代码如下:

function mouseAction() {

var textInputs = document.getElementsByTagName("input");

var len = textInputs.length;

var index = 0;

var textInput;

/*

也能用 for in 语句遍历

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文件

}; //注意要加分号

textInput.onmouseout = function(){

this.className = "txtMouseOut";

};

textInput.onfocus = function(){

this.className = "txtMouseFocus";

};

textInput.onblur = function(){

this.className = "txtMouseBlur";

};

}

}

}

//也可以直接跟一个函数名,不要加引号,括号 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;

}

【鼠标经过的文本框textbox变色】相关文章:

连接文字不停变色

自动检查并替换文本框内的字符

JS实现窗口加载时模拟鼠标移动的方法

javascript基础知识分享之类与函数化

JavaScript实现鼠标拖动效果的方法

js验证上传图片的方法

jQuery实现鼠标经过图片变亮其他变暗效果

父窗口获取弹出子窗口文本框的值

javascript实现图片跟随鼠标移动效果的方法

匹配html标记的正则

精品推荐
分类导航