利用JavaScript模擬京東快遞單號(hào)查詢效果
1、上面放大框開始是隱藏的,當(dāng)輸入單號(hào)后,就顯示,并且里面的內(nèi)容是輸入框的內(nèi)容的字體的放大
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> table { margin: 20px; border: none } p { font-size: 15px; } input { height: 15px } button { background-color: rgb(77, 132, 233); border: none; } a { text-decoration: none; color: white; font-size: 15px; } div { font-size: 25px; width: 100px; height: auto; border: 1px solid black; display: none; position: absolute; top: 0px } </style> </head> <body> <table> <tr> <td> <p>快遞單號(hào)</p> </td> <td> <input type="text" placeholder="請(qǐng)輸入您的快遞單號(hào)"></td> <td> <button><a href="">查詢</a></button></td> </tr> </table> <div></div> <script> //當(dāng)開始在輸入框中鍵入內(nèi)容的時(shí)候,div模塊就開始顯示,里面的內(nèi)容是input里面的內(nèi)容,但字體變大 var input = document.querySelector('input') var div = document.querySelector('div') input.addEventListener('keyup', function() { if (input.value != '') { div.style.display = 'block' div.innerHTML = input.value } else { div.style.display = 'none' div.innerHTML = '' } }) </script> </body> </html>
問題:
1、上面放大框的效果怎么做,倒三角雖然可以使用border來(lái)完成,但是效果會(huì)有顏色的填充
2、當(dāng)輸入框輸入的文字較多的時(shí)候,怎么自動(dòng)的改變上面放大框的高度和寬度
.con::before { content: ''; height: 0; height: 0; position: absolute; top: 28px; left: 18px; border: 8px solid #000; border-style: solid dashed dashed; border-color: #fff transparent transparent }
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> .search { position: relative; width: 178px; margin: 100px } .con { position: absolute; top: -40px; width: 171px; border: 1px solid rgba(0, 0, 0, .2); box-shadow: 0 2px 4px rgba(0, 0, 0, .2); padding: 5px 0; font-size: 18px; line-height: 20px; color: #333; display: none; } .con::before { content: ''; height: 0; height: 0; position: absolute; top: 28px; left: 18px; border: 8px solid #000; border-style: solid dashed dashed; border-color: #fff transparent transparent } </style> </head> <body> <div class="search"> <div class="con"></div> <input type="text" placeholder="請(qǐng)輸入您的快遞單號(hào)" class="jd"> </div> <script> //當(dāng)開始在輸入框中鍵入內(nèi)容的時(shí)候,div模塊就開始顯示,里面的內(nèi)容是input里面的內(nèi)容,但字體變大 var jd = document.querySelector('.jd') var con = document.querySelector('.con') jd.addEventListener('keyup', function() { //要區(qū)分keyup、keydown、keypress之間的區(qū)別 if (jd.value != '') { con.style.display = 'block' con.innerHTML = jd.value } else { con.style.display = 'none' con.innerHTML = '' } }) </script> </body> </html>
如果換成keydown或者keypress來(lái)注冊(cè)事件的話,會(huì)少一個(gè)字,這是因?yàn)槲淖诌€沒有落入文本框的時(shí)候,就以及觸發(fā)了事件,但此時(shí)里面的內(nèi)容還是空的,因此上面的文本框是不顯示的。第二次按下的時(shí)候,立刻觸發(fā)事件,此時(shí)字并沒有進(jìn)入盒子,盒子里面留下的只有前一個(gè)字。
注意區(qū)別
keypress更加不行,因?yàn)閷?duì)于功能鍵是沒有效果的。
4、當(dāng)失去焦點(diǎn)的時(shí)候,就隱藏con。得到焦點(diǎn)就顯示(onfocus、onblur)
<script> //當(dāng)開始在輸入框中鍵入內(nèi)容的時(shí)候,div模塊就開始顯示,里面的內(nèi)容是input里面的內(nèi)容,但字體變大 var jd = document.querySelector('.jd') var con = document.querySelector('.con') jd.addEventListener('keyup', function() { //要區(qū)分keyup、keydown、keypress之間的區(qū)別 if (jd.value != '') { con.style.display = 'block' con.innerHTML = jd.value } else { con.style.display = 'none' con.innerHTML = '' } }) jd.addEventListener('focus', function() { if (jd.value != '') { con.style.display = 'block' } }) jd.addEventListener('blur', function() { con.style.display = '' }) </script>
以上就是利用JavaScript模擬京東快遞單號(hào)查詢效果的詳細(xì)內(nèi)容,更多關(guān)于JavaScript快遞單號(hào)查詢的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
javascript淺層克隆、深度克隆對(duì)比及實(shí)例解析
這篇文章主要介紹了javascript淺層克隆、深度克隆對(duì)比及實(shí)例解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-02-02layui中select,radio設(shè)置不生效的解決方法
今天小編就為大家分享一篇layui中select,radio設(shè)置不生效的解決方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-09-09Javascript document.referrer判斷訪客來(lái)源網(wǎng)址
用簡(jiǎn)單幾行的javascript,就可抓到使用的來(lái)源,以及作出一些防范的措施。2009-12-12Three.js+React實(shí)現(xiàn)3D開放世界小游戲
本文使用?Three.js?+?React?+?CANNON?技術(shù)棧,實(shí)現(xiàn)通過(guò)滑動(dòng)屏幕控制模型在3D世界里運(yùn)動(dòng)的?Low?Poly?低多邊形風(fēng)格小游戲,感興趣的可以了解一下2022-04-04jquery div模態(tài)窗口的簡(jiǎn)單實(shí)例
下面小編就為大家?guī)?lái)一篇jquery div模態(tài)窗口的簡(jiǎn)單實(shí)例。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-05-05使用Fuse.js實(shí)現(xiàn)高效的模糊搜索功能
在現(xiàn)代?Web?應(yīng)用程序中,實(shí)現(xiàn)高效的搜索功能是至關(guān)重要的,Fuse.js?是一個(gè)強(qiáng)大的?JavaScript?庫(kù),它提供了靈活的模糊搜索和文本匹配功能,使您能夠輕松實(shí)現(xiàn)出色的搜索體驗(yàn),文中代碼示例講解的非常詳細(xì),需要的朋友可以參考下2024-01-01javascript跟隨滾動(dòng)效果插件代碼(javascript Follow Plugin)
這篇文章介紹了javascript跟隨滾動(dòng)效果插件代碼(javascript Follow Plugin),有需要的朋友可以參考一下2013-08-08