ソースを参照

Set cursor at the end of the input

Daoud Clarke 3 年 前
コミット
1d8b37add1
2 ファイル変更4 行追加1 行削除
  1. 1 1
      static/index.html
  2. 3 0
      static/index.js

+ 1 - 1
static/index.html

@@ -11,7 +11,7 @@
 Stoatally different.
 
 <form action="/search">
-  <input type="search" id="search" name="s" />
+  <input type="search" id="search" name="s" value="" autofocus/>
 </form>
 
 <div id="results">

+ 3 - 0
static/index.js

@@ -3,6 +3,9 @@
 window.onload = (event) => {
     const searchInput = document.getElementById('search');
 
+    const length = searchInput.value.length;
+    searchInput.setSelectionRange(length, length);
+
     searchInput.addEventListener('keyup', (e) => {
         console.log(searchInput.value);