js實(shí)現(xiàn)京東快遞單號(hào)查詢
本文實(shí)例為大家分享了js實(shí)現(xiàn)京東快遞單號(hào)查詢的具體代碼,供大家參考,具體內(nèi)容如下
1.實(shí)現(xiàn)效果:
當(dāng)文本框中輸入文字時(shí),上面有一個(gè)放大文字的框中顯示文本框內(nèi)容。失去焦點(diǎn)時(shí),放大文字的框消失,獲得焦點(diǎn)時(shí),放大文字的框顯示。
2.案例分析
3.代碼實(shí)現(xiàn)
<!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>模擬京東快遞單號(hào)查詢</title> ? ? <style> ? ? ? ? * { ? ? ? ? ? ? padding: 0; ? ? ? ? ? ? margin: 0; ? ? ? ? } ? ? ? ? .search { ? ? ? ? ? ? position: relative; ? ? ? ? ? ? width: 178px; ? ? ? ? ? ? margin: 100px; ? ? ? ? } ? ? ? ? .con { ? ? ? ? ? ? display: none; ? ? ? ? ? ? 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; ? ? ? ? } ? ? ? ? /* 小三角 :偽元素*/ ? ? ? ? .con::before { ? ? ? ? ? ? content: ''; ? ? ? ? ? ? width: 0; ? ? ? ? ? ? height: 0; ? ? ? ? ? ? position: absolute; ? ? ? ? ? ? top: 28px; ? ? ? ? ? ? left: 18px; ? ? ? ? ? ? border: 8px solid #000; ? ? ? ? ? ? border-style: solid dashed dashed; ? ? ? ? ? ? border-color: #fff transparent transparent;/* 三個(gè)值分別是 上:左右:下*/ ? ? ? ? } ? ? </style> </head> <body> ? ? <div class = "search"> ? ? ? ? <div class="con">123</div> ? ? ? ? <input type="text" placeholder="請(qǐng)輸入您的快遞單號(hào)" class = "jd"> ? ? </div> ? ? <script> ? ? ? ? var con = document.querySelector('.con'); ? ? ? ? var input = document.querySelector('.jd'); ? ? ? ? input.addEventListener('keyup', function() { ? ? ? ? ? ? if(this.value == '') { ? ? ? ? ? ? ? ? con.style.display = 'none'; ? ? ? ? ? ? } else { ? ? ? ? ? ? ? ? con.innerHTML = this.value; ? ? ? ? ? ? ? ? con.style.display = 'block'; ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? }) ? ? ? ? // 失去焦點(diǎn),隱藏盒子。 ? ? ? ? input.addEventListener('blur', function() { ? ? ? ? ? ? if(this.value != '') { ? ? ? ? ? ? ? ? con.style.display = 'none'; ? ? ? ? ? ? } ? ? ? ? }) ? ? ? ? // 有焦點(diǎn)時(shí),出現(xiàn)盒子。 ? ? ? ? input.addEventListener('focus', function(){ ? ? ? ? ? ? if(this.value != '') { ? ? ? ? ? ? ? ? con.style.display = 'block'; ? ? ? ? ? ? } ? ? ? ? }) ? ? </script> </body> </html>
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
window.addeventjs事件驅(qū)動(dòng)函數(shù)集合addEvent等
addEvent()、removeEvent()、handleEvent()、fixEvent()[2008-02-02javascript經(jīng)典特效分享 手風(fēng)琴、輪播圖、圖片滑動(dòng)
這篇文章主要介紹了javascript經(jīng)典特效,手風(fēng)琴、輪播圖、圖片滑動(dòng)效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-09-09ES6新特性三: Generator(生成器)函數(shù)詳解
這篇文章主要介紹了ES6新特性之Generator(生成器)函數(shù),簡單分析了Generator(生成器)函數(shù)的功能、定義、調(diào)用方法并結(jié)合實(shí)例形式給出了相關(guān)使用技巧,需要的朋友可以參考下2017-04-04Axios設(shè)置token請(qǐng)求頭的三種方式
用戶登錄時(shí),后端會(huì)返回一個(gè)token,并且保存到瀏覽器的localstorage中,可以根據(jù)localstorage中的token判斷用戶是否登錄,所以當(dāng)發(fā)送請(qǐng)求時(shí),都要攜帶token給后端進(jìn)行判斷,本文給大家介紹了Axios設(shè)置token請(qǐng)求頭的三種方式,需要的朋友可以參考下2024-02-02