JavaScript實(shí)現(xiàn)為input與textarea自定義hover,focus效果的方法
本文實(shí)例講述了JavaScript實(shí)現(xiàn)為input與textarea自定義hover,focus效果的方法。分享給大家供大家參考。具體如下:
這里演示JavaScript為input輸入框和textarea文本框自定義hover,focus效果,hover也就是鼠標(biāo)放上去之后的效果,focus是鼠標(biāo)焦點(diǎn)問題,要實(shí)現(xiàn) 這種效果,需要JS來配合,這個(gè)例子就是很不錯的,它把網(wǎng)頁上輸入框和文本框都加入了鼠標(biāo)懸停和鼠標(biāo)焦點(diǎn)效果。
運(yùn)行效果截圖如下:
在線演示地址如下:
http://demo.jb51.net/js/2015/js-input-textarea-hover-focus-style-codes/
具體代碼如下:
<title>JavaScript為input/textarea自定義hover,focus效果</title> <script type="text/javascript"> function suckerfish(type, tag, parentId) { if (window.attachEvent) { window.attachEvent("onload", function() { var sfEls = (parentId==null)?document.getElementsByTagName(tag):document.getElementById(parentId).getElementsByTagName(tag); type(sfEls); }); } } sfHover = function(sfEls) { for (var i=0; i < sfEls.length; i++) { sfEls[i].onmouseover=function() { this.className+=" iptHover"; } sfEls[i].onmouseout=function() { this.className=this.className.replace(new RegExp(" iptHover\\b"), ""); } } } sfFocus = function(sfEls) { for (var i=0; i < sfEls.length; i++) { sfEls[i].onfocus=function() { this.className+=" iptFocus"; } sfEls[i].onblur=function() { this.className=this.className.replace(new RegExp(" iptFocus\\b"), ""); } } } </script> <style type="text/css"> textarea{ border:1px solid #BBE1F1; width:250px; height:80px; } .iptHover,input:hover,textarea:hover{ border:1px solid #77C2E3; } .iptFocus,input:focus,textarea:focus{ border:1px solid #77C2E3; background-color:#EFF7FF; } </style> <input type="text" name="textfield" /><br /> <textarea name="textarea"></textarea> <script type="text/javascript"> suckerfish(sfHover, "input"); suckerfish(sfFocus, "input"); suckerfish(sfHover, "textarea"); suckerfish(sfFocus, "textarea"); </script>
希望本文所述對大家的javascript程序設(shè)計(jì)有所幫助。
- 基于JS如何實(shí)現(xiàn)類似QQ好友頭像hover時(shí)顯示資料卡的效果(推薦)
- JS組件Bootstrap dropdown組件擴(kuò)展hover事件
- javascript解決IE6下hover問題的方法
- js模仿hover的具體實(shí)現(xiàn)代碼
- js hover 定時(shí)器(實(shí)例代碼)
- jQuery控制圖片的hover效果(smartRollover.js)
- js操作css屬性實(shí)現(xiàn)div層展開關(guān)閉效果的方法
- 詳解Javascript動態(tài)操作CSS
- JS操作CSS隨機(jī)改變網(wǎng)頁背景實(shí)現(xiàn)思路
- 使用js操作css實(shí)現(xiàn)js改變背景圖片示例
- JS實(shí)現(xiàn)css hover操作的方法示例
相關(guān)文章
js實(shí)現(xiàn)一個(gè)逐步遞增的數(shù)字動畫
可視化大屏項(xiàng)目使用最多的組件就是數(shù)字組件,本文主要介紹了js實(shí)現(xiàn)一個(gè)逐步遞增的數(shù)字動畫,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-12-12layui時(shí)間控件選擇時(shí)間范圍的實(shí)現(xiàn)方法
今天小編就為大家分享一篇layui時(shí)間控件選擇時(shí)間范圍的實(shí)現(xiàn)方法,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-09-09JavaScript實(shí)現(xiàn)Excel表格效果
這篇文章主要為大家詳細(xì)介紹了JavaScript實(shí)現(xiàn)Excel表格效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-02-02