第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

在外部單擊時(shí)如何隱藏輸入?

在外部單擊時(shí)如何隱藏輸入?

眼眸繁星 2021-04-06 14:10:16
我有一個(gè)用例,其中用戶(hù)單擊搜索圖標(biāo),并顯示輸入。我想這樣做,以便在打開(kāi)輸入時(shí),只要您在輸入之外單擊,它就會(huì)將其隱藏。當(dāng)然,我也想保持當(dāng)前的切換狀態(tài)。試圖找出一種使用普通JavaScript(而不是jQuery)的解決方案。///////////// Nav - Search Functionality// Toggle showing and not showing the inputconst searchIcon = document.getElementById('search-icon');const searchInput = document.getElementById('search-input');searchIcon.addEventListener('click', function() {  searchInput.classList.toggle('is-active');  searchInput.classList.toggle('transform-is-active');});.is-active {  display: block !important;}.is-hidden {  display: none !important;}.transform-is-active {  width: 200px !important;}#search-input {  display: none;  margin-right: 10px;  transition: all 2s ease;}#search-icon {  cursor: pointer;}<!--Search--><input id="search-input" class="input" type="text" placeholder="Search..."><img id="search-icon" src="https://static.thenounproject.com/png/101791-200.png" alt="Search" tabindex="0" />
查看完整描述

3 回答

?
犯罪嫌疑人X

TA貢獻(xiàn)2080條經(jīng)驗(yàn) 獲得超4個(gè)贊

妳去 單擊主體時(shí)(在圖標(biāo)外部),它將隱藏輸入,并保留切換。


const searchIcon = document.getElementById('search-icon');

const searchInput = document.getElementById('search-input');


searchInput.addEventListener('click', function(event){

  event.stopPropagation();

});


searchIcon.addEventListener('click', function(event) {

  searchInput.classList.toggle('is-active');

  searchInput.classList.toggle('transform-is-active');

  event.stopPropagation();

});


document.body.addEventListener('click', function(event) {

  searchInput.classList.remove('is-active');

  searchInput.classList.remove('transform-is-active');

  event.preventDefault();

});


查看完整回答
反對(duì) 回復(fù) 2021-04-08
  • 3 回答
  • 0 關(guān)注
  • 213 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)