欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

javascript實(shí)現(xiàn)京東快遞單號(hào)的查詢效果

 更新時(shí)間:2020年11月30日 11:13:13   作者:楊蛋蛋~R  
這篇文章主要為大家詳細(xì)介紹了javascript實(shí)現(xiàn)京東快遞單號(hào)的查詢效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

案例:模擬京東快遞單號(hào)的查詢效果,供大家參考,具體內(nèi)容如下

要求:當(dāng)我們?cè)谖谋究蛑休斎雰?nèi)容時(shí),文本框上面自動(dòng)顯示大字號(hào)的內(nèi)容

分析:

  • 輸入內(nèi)容時(shí),上面的大盒子會(huì)自動(dòng)顯示出來(lái)(這里字號(hào)更大)
  • 表單檢測(cè)用戶輸入,給表單添加鍵盤(pán)事件
  • 同時(shí)把快遞單號(hào)里面的值(value)獲取過(guò)來(lái)復(fù)制給大盒子作為內(nèi)容
  • 如果快遞單號(hào)里面內(nèi)容為空,就隱藏大盒子
  • 當(dāng)失去焦點(diǎn),大盒子也隱藏

注意:keydown 和 keypress 在文本框里面的特點(diǎn) : 他們兩個(gè)事件觸發(fā)的時(shí)候,文字還沒(méi)有落入文本框中,keyup 事件觸發(fā)的時(shí)候,文本已經(jīng)落入文本框里了

<style>
  * {
  padding: 0;
  margin: 0;
  }
  .search {
  position: relative;
  width: 178px;
  margin: 100px;
  }
  .con {
  display: none;
  position: absolute;
  top: -48px;
  width: 171px;
  border: 1px solid rgba(0, 0, 0, 0.2);
  box-shadow: 0 2px 4px rgba(0, 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;
  }
 </style>
 </head>
 <body>
 <div class="search">
  <div class="con"></div>
  <input type="text" placeholder="請(qǐng)輸入您的快遞單號(hào)" class="jd" />
 </div>
 <script>
  var con = document.querySelector(".con");
  var jd_input = document.querySelector(".jd");
  jd_input.addEventListener("keyup", function () {
  if (this.value == "") {
   con.style.display = "none";
  } else {
   con.style.display = "block";
   con.innerHTML = this.value;
  }
  });
  //當(dāng)失去焦點(diǎn),就隱藏盒子
  jd_input.addEventListener("blur", function () {
  con.style.display = "none";
  });
  //當(dāng)獲得焦點(diǎn),就顯示盒子
  jd_input.addEventListener("focus", function () {
  if (this.value !== "") {
   con.style.display = "block";
  }
  });
 </script>
</body>

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論