鼠標(biāo)經(jīng)過(guò)的文本框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)文章
強(qiáng)效、方便的表單通用檢測(cè)JS 不錯(cuò)
強(qiáng)效、方便的表單通用檢測(cè)JS 不錯(cuò)...2007-01-01JS 無(wú)限級(jí) Select效果實(shí)現(xiàn)代碼(json格式)
JS 無(wú)限級(jí) Select效果實(shí)現(xiàn)代碼(json格式),學(xué)習(xí)js的朋友可以參考下。2011-08-08用JavaScript限制textarea輸入長(zhǎng)度 (For: IE、Firefox ...)[
用JavaScript限制textarea輸入長(zhǎng)度 (For: IE、Firefox ...)[...2006-12-12input、button的不同type值在ajax提交表單時(shí)導(dǎo)致的陷阱
最近在公司的項(xiàng)目中嘗試著利用YUI來(lái)實(shí)現(xiàn)各種效果。2009-02-02js select 標(biāo)簽選定項(xiàng)的值獲取代碼
用js獲取當(dāng)前選定的select的值的函數(shù)2009-03-03css+js實(shí)現(xiàn)select列表橫向排列效果代碼
真不錯(cuò)的select橫排效果代碼,推薦大家閱讀,這個(gè)思路真不錯(cuò),太感謝作者了2008-06-06