js控制輸入框獲得和失去焦點時狀態(tài)顯示的方法
更新時間:2015年01月30日 10:51:42 作者:comeonstone
這篇文章主要介紹了js控制輸入框獲得和失去焦點時狀態(tài)顯示的方法,可實現(xiàn)判斷輸入框的焦點狀態(tài)設(shè)置不同樣式的功能,是非常實用的技巧,需要的朋友可以參考下
本文實例講述了js控制輸入框獲得和失去焦點時狀態(tài)顯示的方法。分享給大家供大家參考。具體實現(xiàn)方法如下:
<!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=gb2312" /> <title>邊框變色</title> <style type="text/css"> <!-- .SearchKeyword {border:1px solid #797A75;width: 202px;color: #CDCDCD;font-size:12px;} .SearchKeywordonFocus {border:1px solid #ABCD3A;width: 202px;color: #000000;font-size:12px;} --> </style> <script language="javascript"> function keywordfocus() { if (document.formSearch.keyword.value == '請輸入關(guān)鍵字') { document.formSearch.keyword.value = ''; document.formSearch.keyword.className = 'SearchKeywordonFocus'; } } function keywordblur() { if (document.formSearch.keyword.value == '') { document.formSearch.keyword.value = '請輸入關(guān)鍵字'; document.formSearch.keyword.className = 'SearchKeyword'; } } </SCRIPT> </head> <body> <form id="formSearch" name="formSearch" method="post" action=""> <input type="text" name="keyword" class="SearchKeyword" value="請輸入關(guān)鍵字" onFocus="keywordfocus();" onBlur="keywordblur();" /> </form> </body> </html>
希望本文所述對大家的javascript程序設(shè)計有所幫助。
相關(guān)文章
dropdownlist之間的互相聯(lián)動實現(xiàn)(顯示與隱藏)
dropdownlist之間的互相聯(lián)動(顯示與隱藏)2009-11-11javascript組合使用構(gòu)造函數(shù)模式和原型模式實例
這篇文章主要介紹了javascript組合使用構(gòu)造函數(shù)模式和原型模式的方法,通過一個簡單實例分析了javascript構(gòu)造函數(shù)模式與原型模式的使用方法,需要的朋友可以參考下2015-06-06JS的執(zhí)行機制(EventLoop、宏任務(wù)和微任務(wù))
這篇文章主要介紹了JS的執(zhí)行機制(EventLoop、宏任務(wù)和微任務(wù)),具有很好的參考價值,希望對大家有所幫助。2023-01-01