相關(guān)資訊
本類常用軟件
-
福建農(nóng)村信用社手機銀行客戶端下載下載量:584204
-
Windows優(yōu)化大師下載量:416898
-
90美女秀(視頻聊天軟件)下載量:366961
-
廣西農(nóng)村信用社手機銀行客戶端下載下載量:365699
-
快播手機版下載量:325855
Js方法
<head>
<script type="text/javascript">
function Doit() {
// 獲得一個input的數(shù)組,需要遍歷
var inputs = document.getElementsByTagName_r("input");
for (var i = 0; i < inputs.length; i++) {
// 如果是文本控件
if (inputs[i].type == "text") {
// 前面有on——
inputs[i].onfocus = function () {
// 通過this直接獲取觸發(fā)的元素
this.style.backgroundColor = "yellow";
};
inputs[i].onblur = function () {
this.style.backgroundColor = "white";
};
}
}
}
</script>
</head>
<body onload="Doit()">
<input id="Text1" type="text" />
<input id="Text2" type="text" />
<input id="Text3" type="text" />
<input id="Button1" type="button" value="button" />
</body>
</html>
Jquery方法
<head>
<script src="jquery-1.4.1.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
// 不需要遍歷
$('input[type=text]').click(function () {
// this前面要加dollar符
$(this).css("backgroundColor","yellow");
}).blur(function () { $(this).css("backgroundColor","white");});
// blur前面沒有on
});
</script>
</head>
<body>
<input id="Text1" type="text" />
<input id="Text2" type="text" />
<input id="Text3" type="text" />
<input id="Button1" type="button" value="button" />
</body>
</html>
<head>
<script type="text/javascript">
function Doit() {
// 獲得一個input的數(shù)組,需要遍歷
var inputs = document.getElementsByTagName_r("input");
for (var i = 0; i < inputs.length; i++) {
// 如果是文本控件
if (inputs[i].type == "text") {
// 前面有on——
inputs[i].onfocus = function () {
// 通過this直接獲取觸發(fā)的元素
this.style.backgroundColor = "yellow";
};
inputs[i].onblur = function () {
this.style.backgroundColor = "white";
};
}
}
}
</script>
</head>
<body onload="Doit()">
<input id="Text1" type="text" />
<input id="Text2" type="text" />
<input id="Text3" type="text" />
<input id="Button1" type="button" value="button" />
</body>
</html>
Jquery方法
<head>
<script src="jquery-1.4.1.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
// 不需要遍歷
$('input[type=text]').click(function () {
// this前面要加dollar符
$(this).css("backgroundColor","yellow");
}).blur(function () { $(this).css("backgroundColor","white");});
// blur前面沒有on
});
</script>
</head>
<body>
<input id="Text1" type="text" />
<input id="Text2" type="text" />
<input id="Text3" type="text" />
<input id="Button1" type="button" value="button" />
</body>
</html>
熱門評論
最新評論