js實現(xiàn)當前輸入框高亮顯示的方法
本文實例講述了js實現(xiàn)當前輸入框高亮顯示的方法。分享給大家供大家參考。具體如下:
這里演示利用JavaScript技術(shù)實現(xiàn)的當前輸入框高亮顯示代碼,在很多的網(wǎng)頁表單中,當用戶鼠標點擊文本框的時候,該文本框就會顯示高亮狀態(tài),提醒用戶輸入,本例通過JAVAScript代碼實現(xiàn)了這樣一種效果。
運行效果如下圖所示:

在線演示地址如下:
http://demo.jb51.net/js/2015/js-table-input-color-show-codes/
具體代碼如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>當前輸入框高亮顯示</title>
<style>
body,form,h2,p,input{margin:0;padding:0;}
body{color:#4f4f4f;font:14px/1.5 \5fae\8f6f\96c5\9ed1;}
form{width:400px;background:#fef4eb;border:2px solid #f60;padding-bottom:10px;overflow:hidden;zoom:1;margin:10px auto;}
form h2{color:#fe791e;font-size:16px;background:#ffebd7;border-bottom:2px solid #f60;padding:5px 10px;}
form p{float:left;clear:both;width:100%;height:31px;margin-top:10px;line-height:31px;}
form label,form input{float:left;}
form label{width:100px;height:31px;text-align:right;}
form input{border:0;font-family:\5fae\8f6f\96c5\9ed1;background:url(input.png) no-repeat;}
form .f-text,form .f-text-high{width:203px;height:31px;padding-left:5px;line-height:31px;}
form .f-text-high{background-position:0 -31px;}
form .f-btn{color:#fff;width:104px;height:31px;cursor:pointer;font-size:16px;background:#f60;line-height:31px;border-radius:5px;}
</style>
<script type="text/javascript">
window.onload = function ()
{
var aInput = document.getElementsByTagName("input");
var i = 0;
for (i = 0; i < aInput.length - 1; i++)
{
aInput[i].onfocus = function ()
{
this.className = "f-text-high"
};
aInput[i].onblur = function ()
{
this.className = "f-text"
}
}
};
</script>
</head>
<body>
<form>
<h2>用戶登錄</h2>
<p><label>用戶名:</label><input class="f-text" type="text" /></p>
<p><label>密碼:</label><input class="f-text" type="password" /></p>
<p><label></label><input class="f-btn" type="button" value="登 錄" /></p>
</form>
</body>
</html>
希望本文所述對大家的javascript程序設計有所幫助。
相關(guān)文章
JavaScript字符串轉(zhuǎn)數(shù)字的多種方法總結(jié)
在 JavaScript 開發(fā)中,我們經(jīng)常需要將字符串轉(zhuǎn)換為數(shù)字,例如從輸入框獲取用戶輸入后進行數(shù)學計算,JavaScript 提供了多種方法來實現(xiàn)這一功能,如 parseInt、parseFloat、Number 等,本文將詳細介紹這些方法的使用方式、適用場景以及可能的坑,需要的朋友可以參考下2025-03-03
javascript實現(xiàn)自動輸出文本(打字特效)
文字如何實現(xiàn)打字的效果呢?在瀏覽網(wǎng)頁的時候也經(jīng)常能看到這種效果。本文給大家匯總介紹了幾種打字效果的文字特效,文字一個一個地打印在頁面上。2015-08-08
arrayToJson將數(shù)組轉(zhuǎn)化為json格式的js代碼
arrayToJson將數(shù)組轉(zhuǎn)化為json格式的js代碼,需要的朋友可以參考下。2010-10-10

