方法

ハウツーホーム

メニュー

アイコンバー メニューアイコン アコーディオン タブ 垂直タブ タブヘッダー フルページタブ ホバータブ トップナビゲーション レスポンシブTopnav アイコン付きのナビゲーションバー 検索メニュー 検索バー 固定サイドバー ページナビゲーション レスポンシブサイドバー フルスクリーンナビゲーション オフキャンバスメニュー Sidenavボタンにカーソルを合わせる アイコン付きサイドバー 水平スクロールメニュー 垂直メニュー ボトムナビゲーション レスポンシブボトムナビゲーション ボトムボーダーナビゲーションリンク 右揃えのメニューリンク 中央メニューリンク 等幅メニューリンク 固定メニュー スクロールでバーを下にスライド スクロールでナビゲーションバーを非表示 スクロールでナビゲーションバーを縮小 スティッキーナビゲーションバー 画像上のナビゲーションバー ホバードロップダウン ドロップダウンをクリックします カスケードドロップダウン Topnavのドロップダウン Sidenavのドロップダウン 応答ナビゲーションバーのドロップダウン サブナビゲーションメニュー ドロップアップ メガメニュー モバイルメニュー カーテンメニュー 折りたたまれたサイドバー 折りたたまれたサイドパネル ページ付け パン粉 ボタングループ 垂直ボタングループ スティッキーソーシャルバー ピルナビゲーション レスポンシブヘッダー

画像

スライドショー スライドショーギャラリー モーダル画像 ライトボックス レスポンシブ画像グリッド 画像グリッド タブギャラリー 画像オーバーレイフェード 画像オーバーレイスライド 画像オーバーレイズーム 画像オーバーレイタイトル 画像オーバーレイアイコン 画像効果 黒と白の画像 画像テキスト 画像テキストブロック 透明な画像テキスト フルページ画像 画像上のフォーム ヒーロー画像 背景画像をぼかす スクロールでBgを変更する サイドバイサイド画像 丸みを帯びた画像 アバター画像 レスポンシブ画像 中央の画像 サムネイル 画像の周りの境界線 チームに会う スティッキー画像 画像を反転する 画像を振る ポートフォリオギャラリー フィルタリングを備えたポートフォリオ 画像ズーム 画像拡大鏡ガラス 画像比較スライダー ファビコン

ボタン

アラートボタン アウトラインボタン 分割ボタン アニメーションボタン フェージングボタン 画像のボタン ソーシャルメディアボタン 続きを読む続きを読む 読み込みボタン ダウンロードボタン ピルボタン 通知ボタン アイコンボタン 次/前のボタン ナビゲーションのその他のボタン ブロックボタン テキストボタン 丸いボタン トップボタンまでスクロール

フォーム

ログインフォーム サインアップフォーム チェックアウトフォーム お問い合わせフォーム ソーシャルログインフォーム 登録フォーム アイコン付きのフォーム ニュースレター スタックフォーム レスポンシブフォーム ポップアップフォーム インラインフォーム 入力フィールドをクリア 数字の矢印を隠す テキストをクリップボードにコピーする アニメーション検索 検索ボタン 全画面検索 ナビゲーションバーの入力フィールド Navbarのログインフォーム カスタムチェックボックス/ラジオ カスタム選択 トグルスイッチ チェックボックスをオンにします CapsLockを検出する Enterのトリガーボタン パスワードの検証 パスワードの可視性を切り替える マルチステップフォーム オートコンプリート オートコンプリートをオフにする スペルチェックをオフにする ファイルアップロードボタン 空の入力検証

フィルタ

フィルタリスト フィルターテーブル フィルタ要素 フィルタのドロップダウン ソートリスト スペルテーブル

テーブル

ゼブラストライプテーブル センターテーブル 全幅テーブル 並べたテーブル レスポンシブテーブル 比較表

もっと

フルスクリーンビデオ モーダルボックス モーダルを削除 タイムライン スクロールインジケーター プログレスバー スキルバー レンジスライダー ツールチップ 表示要素ホバー ポップアップ 折りたたみ可能 カレンダー HTMLに含まれるもの やることリスト ローダー 星評価 ユーザー評価 オーバーレイ効果 コンタクトチップ カード フリップカード プロフィールカード 製品カード アラート 叫ぶ ノート ラベル サークル スタイルHR クーポン リストグループ 箇条書きなしのリスト レスポンシブテキスト カットアウトテキスト 輝くテキスト 固定フッター スティッキーエレメ​​ント 等しい高さ Clearfix レスポンシブフロート スナックバー フルスクリーンウィンドウ スクロール図面 スムーズスクロール グラデーションBgスクロール スティッキーヘッダー スクロールでヘッダーを縮小 価格表 視差 アスペクト比 レスポンシブIframe 好き/嫌いを切り替える 非表示/表示を切り替えます ダークモードを切り替えます テキストを切り替えます トグルクラス クラスを追加 クラスを削除 アクティブクラス ツリー表示 プロパティを削除 オフライン検出 隠された要素を見つける Webページをリダイレクトする ズームホバー フリップボックス 垂直方向に中央に配置 DIVの中央ボタン ホバーでの遷移 矢印 ダウンロードリンク フルハイト要素 ブラウザウィンドウ カスタムスクロールバー スクロールバーを非表示 スクロールバーの表示/強制 デバイスルック コンテンツ編集可能な境界線 プレースホルダーの色 テキスト選択色 弾丸の色 垂直線 仕切り アイコンをアニメーション化する カウントダウンタイマー タイプライター 近日公開ページ チャットメッセージ ポップアップチャットウィンドウ 画面を分割 お客様の声 セクションカウンター スライドショーを引用 クローズ可能なリストアイテム 典型的なデバイスブレークポイント ドラッグ可能なHTML要素 JSメディアクエリ シンタックスハイライト JSアニメーション JS文字列の長さ JSべき乗 JSのデフォルトパラメータ 現在のURLを取得 現在の画面サイズを取得する Iframe要素を取得する

Webサイト

無料のウェブサイトを作成する ウェブサイトを作る 静的なWebサイトを作成する ウェブサイトを作る(W3.CSS) ウェブサイトを作る(BS3) ウェブサイトを作る(BS4) ウェブサイトを作る(BS5) Webサイトを作成して表示する リンクツリーWebサイトを作成する ポートフォリオを作成する 履歴書を作成する レストランのウェブサイトを作る ビジネスのウェブサイトを作る WebBookを作成する センターのウェブサイト 連絡先セクション ページについて ビッグヘッダー ウェブサイトの例

グリッド

2列のレイアウト 3列のレイアウト 4列のレイアウト グリッドの拡張 リストグリッドビュー 混合列レイアウト コラムカード ジグザグレイアウト ブログのレイアウト

グーグル

Googleチャート Google Fonts Googleフォントペアリング Googleセットアップアナリティクス

コンバーター

重量を変換する 温度変換 長さの変換 変換速度

ブログ

開発者の仕事を得る フロントエンド開発者になる。

方法-オートコンプリート


オートコンプリートを作成する方法を学びます。


オートコンプリート

入力を開始します。



オートコンプリートフォームを作成する

ステップ1)HTMLを追加します。

<!--Make sure the form has the autocomplete function switched off:-->
<form autocomplete="off" action="/action_page.php">
  <div class="autocomplete" style="width:300px;">
    <input id="myInput" type="text" name="myCountry" placeholder="Country">
  </div>
  <input type="submit">
</form>

ステップ2)JavaScript配列を作成します。

世界のすべての国の配列:

var countries = ["Afghanistan","Albania","Algeria","Andorra","Angola","Anguilla","Antigua &amp; Barbuda","Argentina","Armenia","Aruba","Australia","Austria","Azerbaijan","Bahamas","Bahrain","Bangladesh","Barbados","Belarus","Belgium","Belize","Benin","Bermuda","Bhutan","Bolivia","Bosnia &amp; Herzegovina","Botswana","Brazil","British Virgin Islands","Brunei","Bulgaria","Burkina Faso","Burundi","Cambodia","Cameroon","Canada","Cape Verde","Cayman Islands","Central Arfrican Republic","Chad","Chile","China","Colombia","Congo","Cook Islands","Costa Rica","Cote D Ivoire","Croatia","Cuba","Curacao","Cyprus","Czech Republic","Denmark","Djibouti","Dominica","Dominican Republic","Ecuador","Egypt","El Salvador","Equatorial Guinea","Eritrea","Estonia","Ethiopia","Falkland Islands","Faroe Islands","Fiji","Finland","France","French Polynesia","French West Indies","Gabon","Gambia","Georgia","Germany","Ghana","Gibraltar","Greece","Greenland","Grenada","Guam","Guatemala","Guernsey","Guinea","Guinea Bissau","Guyana","Haiti","Honduras","Hong Kong","Hungary","Iceland","India","Indonesia","Iran","Iraq","Ireland","Isle of Man","Israel","Italy","Jamaica","Japan","Jersey","Jordan","Kazakhstan","Kenya","Kiribati","Kosovo","Kuwait","Kyrgyzstan","Laos","Latvia","Lebanon","Lesotho","Liberia","Libya","Liechtenstein","Lithuania","Luxembourg","Macau","Macedonia","Madagascar","Malawi","Malaysia","Maldives","Mali","Malta","Marshall Islands","Mauritania","Mauritius","Mexico","Micronesia","Moldova","Monaco","Mongolia","Montenegro","Montserrat","Morocco","Mozambique","Myanmar","Namibia","Nauro","Nepal","Netherlands","Netherlands Antilles","New Caledonia","New Zealand","Nicaragua","Niger","Nigeria","North Korea","Norway","Oman","Pakistan","Palau","Palestine","Panama","Papua New Guinea","Paraguay","Peru","Philippines","Poland","Portugal","Puerto Rico","Qatar","Reunion","Romania","Russia","Rwanda","Saint Pierre &amp; Miquelon","Samoa","San Marino","Sao Tome and Principe","Saudi Arabia","Senegal","Serbia","Seychelles","Sierra Leone","Singapore","Slovakia","Slovenia","Solomon Islands","Somalia","South Africa","South Korea","South Sudan","Spain","Sri Lanka","St Kitts &amp; Nevis","St Lucia","St Vincent","Sudan","Suriname","Swaziland","Sweden","Switzerland","Syria","Taiwan","Tajikistan","Tanzania","Thailand","Timor L'Este","Togo","Tonga","Trinidad &amp; Tobago","Tunisia","Turkey","Turkmenistan","Turks &amp; Caicos","Tuvalu","Uganda","Ukraine","United Arab Emirates","United Kingdom","United States of America","Uruguay","Uzbekistan","Vanuatu","Vatican City","Venezuela","Vietnam","Virgin Islands (US)","Yemen","Zambia","Zimbabwe"];

ステップ3)CSSを追加します。

コンテナは「相対的な」位置にある必要があります。

* { box-sizing: border-box; }
body {
  font: 16px Arial;
}
.autocomplete {
  /*the container must be positioned relative:*/
  position: relative;
  display: inline-block;
}
input {
  border: 1px solid transparent;
  background-color: #f1f1f1;
  padding: 10px;
  font-size: 16px;
}
input[type=text] {
  background-color: #f1f1f1;
  width: 100%;
}
input[type=submit] {
  background-color: DodgerBlue;
  color: #fff;
}
.autocomplete-items {
  position: absolute;
  border: 1px solid #d4d4d4;
  border-bottom: none;
  border-top: none;
  z-index: 99;
  /*position the autocomplete items to be the same width as the container:*/
  top: 100%;
  left: 0;
  right: 0;
}
.autocomplete-items div {
  padding: 10px;
  cursor: pointer;
  background-color: #fff;
  border-bottom: 1px solid #d4d4d4;
}
.autocomplete-items div:hover {
  /*when hovering an item:*/
  background-color: #e9e9e9;
}
.autocomplete-active {
  /*when navigating through the items using the arrow keys:*/
  background-color: DodgerBlue !important;
  color: #ffffff;
}


ステップ4)JavaScriptを追加します。

function autocomplete(inp, arr) {
  /*the autocomplete function takes two arguments,
  the text field element and an array of possible autocompleted values:*/
  var currentFocus;
  /*execute a function when someone writes in the text field:*/
  inp.addEventListener("input", function(e) {
      var a, b, i, val = this.value;
      /*close any already open lists of autocompleted values*/
      closeAllLists();
      if (!val) { return false;}
      currentFocus = -1;
      /*create a DIV element that will contain the items (values):*/
      a = document.createElement("DIV");
      a.setAttribute("id", this.id + "autocomplete-list");
      a.setAttribute("class", "autocomplete-items");
      /*append the DIV element as a child of the autocomplete container:*/
      this.parentNode.appendChild(a);
      /*for each item in the array...*/
      for (i = 0; i < arr.length; i++) {
        /*check if the item starts with the same letters as the text field value:*/
        if (arr[i].substr(0, val.length).toUpperCase() == val.toUpperCase()) {
          /*create a DIV element for each matching element:*/
          b = document.createElement("DIV");
          /*make the matching letters bold:*/
          b.innerHTML = "<strong>" + arr[i].substr(0, val.length) + "</strong>";
          b.innerHTML += arr[i].substr(val.length);
          /*insert a input field that will hold the current array item's value:*/
          b.innerHTML += "<input type='hidden' value='" + arr[i] + "'>";
          /*execute a function when someone clicks on the item value (DIV element):*/
              b.addEventListener("click", function(e) {
              /*insert the value for the autocomplete text field:*/
              inp.value = this.getElementsByTagName("input")[0].value;
              /*close the list of autocompleted values,
              (or any other open lists of autocompleted values:*/
              closeAllLists();
          });
          a.appendChild(b);
        }
      }
  });
  /*execute a function presses a key on the keyboard:*/
  inp.addEventListener("keydown", function(e) {
      var x = document.getElementById(this.id + "autocomplete-list");
      if (x) x = x.getElementsByTagName("div");
      if (e.keyCode == 40) {
        /*If the arrow DOWN key is pressed,
        increase the currentFocus variable:*/
        currentFocus++;
        /*and and make the current item more visible:*/
        addActive(x);
      } else if (e.keyCode == 38) { //up
        /*If the arrow UP key is pressed,
        decrease the currentFocus variable:*/
        currentFocus--;
        /*and and make the current item more visible:*/
        addActive(x);
      } else if (e.keyCode == 13) {
        /*If the ENTER key is pressed, prevent the form from being submitted,*/
        e.preventDefault();
        if (currentFocus > -1) {
          /*and simulate a click on the "active" item:*/
          if (x) x[currentFocus].click();
        }
      }
  });
  function addActive(x) {
    /*a function to classify an item as "active":*/
    if (!x) return false;
    /*start by removing the "active" class on all items:*/
    removeActive(x);
    if (currentFocus >= x.length) currentFocus = 0;
    if (currentFocus < 0) currentFocus = (x.length - 1);
    /*add class "autocomplete-active":*/
    x[currentFocus].classList.add("autocomplete-active");
  }
  function removeActive(x) {
    /*a function to remove the "active" class from all autocomplete items:*/
    for (var i = 0; i < x.length; i++) {
      x[i].classList.remove("autocomplete-active");
    }
  }
  function closeAllLists(elmnt) {
    /*close all autocomplete lists in the document,
    except the one passed as an argument:*/
    var x = document.getElementsByClassName("autocomplete-items");
    for (var i = 0; i < x.length; i++) {
      if (elmnt != x[i] && elmnt != inp) {
      x[i].parentNode.removeChild(x[i]);
    }
  }
}
/*execute a function when someone clicks in the document:*/
document.addEventListener("click", function (e) {
    closeAllLists(e.target);
});
}

ステップ5)「myInput」のオートコンプリート効果を開始します。

オートコンプリート関数の2番目のパラメーターとしてcountries配列を渡します。

<script>
autocomplete(document.getElementById("myInput"), countries);
</script>