๐ input ์ปค์ ์๋ ์์น ๊ธฐ๋ฅ
์ํ๋ ๋ฐฉํฅ
๐ ํ์ด์ง ๋ฆฌ๋ก๋ ๋๋ฉด ์ปค์๊ฐ ์ธํ์ผ๋ก ์๋ ์์น๋๋๋ก ํ๊ณ ์ถ์๋ค.
๊ตฌํ ๋ฐฉ๋ฒ
- input ํ๊ทธ์ ์์ฑ์ผ๋ก autofocus ๋ฅผ ์ถ๊ฐํด ์ค๋ค.
<!-- ํ์ด์ง ๋ก๋๋์๋ง์ ์ปค์ ์ค๋๋ก autofocus์ค์ -->
<input id="searchInput" type="text" autofocus />
๐ autofocus ์ ํน์ง์ ํ์ด์ง๊ฐ ๋ก๋ ๋์๋ง์ ์๋์ผ๋ก ํฌ์ปค์ฑ์ด ๋๋ค.
2. .focus() ๋ฉ์๋๋ฅผ ์ด์ฉํ๋ค.
//input ์๋ ์ปค์
let input = document.querySelector("#searchInput");
input.focus();
.focus() ๋ ์ฒ์๋ณธ ๋ฉ์๋๋ผ ์ฐพ์๋ดค๋๋ฐ, ์ฐธ๊ณ ํ ๋งํฌ๋ ์๋์ ๊ฐ๋ค.
๐ง . focus( )
- ํน์ ํ ํฌ์ปค์ค๋ก ์ด๋ํด์ผ ํ ๊ฒฝ์ฐ์ ์ฌ์ฉํ๋ฉด ์ข๋ค.
- ํฌ์ปค์ค๋ฅผ ์ ๊ฑฐํ๋ ค๋ฉด . blur( ) ๋ฉ์๋๋ฅผ ์ด์ฉํ๋ฉด ๋๋ค.
https://ko.javascript.info/focus-blur
focus์ blur
ko.javascript.info
https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/focus
HTMLElement: focus() method - Web APIs | MDN
The HTMLElement.focus() method sets focus on the specified element, if it can be focused. The focused element is the element that will receive keyboard and similar events by default.
developer.mozilla.org
'TIL' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
23/10/22 TIL __ import / export (2) (1) | 2023.10.22 |
---|---|
23/10/21 TIL __ import , export ์ฌ์ฉํด๋ณด๊ธฐ (1) (0) | 2023.10.21 |
23/10/19 TIL __ ๊ฒ์๊ธฐ๋ฅ_ ์ ์ด์ฟผ๋ฆฌ ์์ด ์์ ๋ฐ๋๋ผ ์๋ฐ์คํฌ๋ฆฝํธ (0) | 2023.10.19 |
23/10/18 TIL __ ํ๋ก๊ทธ๋๋จธ์ค lv1. ์ถ์ต์ ์ (1) | 2023.10.18 |
23/10/17 TIL __ ๋งํฌ๋ ๋ฆฌ์คํธ (0) | 2023.10.17 |