javascript搜索框效果實(shí)現(xiàn)方法
更新時(shí)間:2015年05月14日 09:54:24 作者:永遠(yuǎn)愛好寫程序
這篇文章主要介紹了javascript搜索框效果實(shí)現(xiàn)方法,可實(shí)現(xiàn)顯示默認(rèn)提示文字的搜索框效果,非常簡單實(shí)用,需要的朋友可以參考下
本文實(shí)例講述了javascript搜索框效果實(shí)現(xiàn)方法。分享給大家供大家參考。具體實(shí)現(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=utf-8" /> <title>搜索框效果</title> <script type="text/javascript"> function iniEvent() { var txtSearch = document.getElementById("txtSearch"); txtSearch.onfocus = function () { if (this.value == "請輸入關(guān)鍵字" || this.value == "") { this.value = ""; this.style.color = "black"; //修改文本框字體顏色 } } txtSearch.onblur = function () { if (this.value == "請輸入關(guān)鍵字" || this.value == "") { this.value = "請輸入關(guān)鍵字"; this.style.color = "red"; //修改文本框字體顏色 } else { this.style.color = "black"; } } } </script> </head> <body onload="iniEvent()"> <!--文字離開如果文本框?yàn)榭談t顯示紅色的"請輸入關(guān)鍵字"--> <!--<label for="txtSearch">查找</label> <input type="text" id="txtSearch" value="請輸入關(guān)鍵字" style="color:red" />--> 查找<input type="text" id="txtSearch" value="請輸入關(guān)鍵字" style="color:red" /><br /><input type="text" /> </body> </html>
希望本文所述對大家的javascript程序設(shè)計(jì)有所幫助。
您可能感興趣的文章:
- js實(shí)現(xiàn)搜索框關(guān)鍵字智能匹配代碼
- 基于Vue.js實(shí)現(xiàn)簡單搜索框
- JavaScript實(shí)現(xiàn)搜索框的自動(dòng)完成功能(一)
- JS實(shí)現(xiàn)仿google、百度搜索框輸入信息智能提示的實(shí)現(xiàn)方法
- JavaScript實(shí)現(xiàn)百度搜索框效果
- JS+Ajax實(shí)現(xiàn)百度智能搜索框
- 自動(dòng)完成的搜索框javascript實(shí)現(xiàn)
- JS實(shí)現(xiàn)京東首頁之頁面頂部、Logo和搜索框功能
- JS實(shí)現(xiàn)微信彈出搜索框 多條件查詢功能
- JavaScript仿京東搜索框?qū)嵗?/a>
相關(guān)文章
JavaScript 中調(diào)用 Kotlin 方法實(shí)例詳解
這篇文章主要介紹了JavaScript 中調(diào)用 Kotlin 方法實(shí)例詳解的相關(guān)資料,需要的朋友可以參考下2017-06-06基于JavaScript實(shí)現(xiàn)Json數(shù)據(jù)根據(jù)某個(gè)字段進(jìn)行排序
這篇文章主要介紹了基于JavaScript實(shí)現(xiàn)Json數(shù)據(jù)根據(jù)某個(gè)字段進(jìn)行排序的相關(guān)資料,需要的朋友可以參考下2015-11-11調(diào)用jQuery滑出效果時(shí)閃爍的解決方法
這篇文章主要介紹了在調(diào)用jQuery 滑出效果時(shí),層會現(xiàn)次閃爍一下的解決方法,需要的朋友可以參考下2014-03-03el-form實(shí)現(xiàn)表單和圖片手動(dòng)上傳和校驗(yàn)功能
在寫項(xiàng)目時(shí),難免遇到需要上傳表單,圖片等文件,且表單內(nèi)容需進(jìn)行驗(yàn)證及必填項(xiàng)提示,圖片需要和信息一起傳遞且圖片載入后需可預(yù)覽,這篇文章給大家介紹el-form實(shí)現(xiàn)表單和圖片手動(dòng)上傳和校驗(yàn)功能,感興趣的朋友一起看看吧2024-01-01