国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

鼠標經過的文本框textbox變色

2019-11-21 01:21:32
字體:
來源:轉載
供稿:網友
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;
}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 同仁县| 鸡西市| 溧阳市| 麦盖提县| 唐海县| 尼玛县| 凤城市| 漳州市| 平南县| 喀喇沁旗| 墨脱县| 灵台县| 瓦房店市| 巴林左旗| 新巴尔虎左旗| 抚远县| 贵州省| 无为县| 乳源| 南华县| 鄱阳县| 固原市| 郯城县| 虹口区| 大田县| 宣威市| 西藏| 宜兴市| 巴林右旗| 青田县| 巢湖市| 偏关县| 克东县| 新泰市| 五河县| 漾濞| 西青区| 绥芬河市| 驻马店市| 铜川市| 铜川市|