Front-End/HTML

[HTML] 09-01. input : form ํƒœ๊ทธ ์•ˆ์—์„œ ์‚ฌ์šฉ๋˜๋Š” ์ž…๋ ฅํƒœ๊ทธ

Bigone17 2021. 12. 15. 21:51

๐ŸŸก 1. form ํƒœ๊ทธ ์•ˆ์—์„œ ์‚ฌ์šฉ๋˜๋Š” ์ž…๋ ฅ ํƒœ๊ทธ์˜ ์ข…๋ฅ˜

  • input : ์›น์‚ฌ์ดํŠธ์—์„œ ํ”ํžˆ ์ž…๋ ฅ์„ ๋ฐ›๋Š” ๊ฑฐ์˜ ๋ชจ๋“  ์ข…๋ฅ˜๋ฅผ input ํƒœ๊ทธ๋ผ๊ณ  ํ•ฉ๋‹ˆ๋‹ค.
    • checkbox, date, email, radio, range ๋“ฑ๋“ฑ
  • select : ์—ฌ๋Ÿฌ ๊ฐœ์˜ ๋ฆฌ์ŠคํŠธ์—์„œ ์—ฌ๋Ÿฌ ๊ฐœ์˜ ์•„์ดํ…œ์„ ์„ ํƒํ•  ๋•Œ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค.
    • select ํƒœ๊ทธ
  • textarea : ๊ธด ๊ธ€์„ ์ž…๋ ฅํ•  ๋•Œ ์‚ฌ์šฉ๋˜๋Š” ํƒœ๊ทธ์ž…๋‹ˆ๋‹ค. ์ฃผ๋กœ ์ž๊ธฐ์†Œ๊ฐœ์„œ ์ž…๋ ฅ์ฐฝ ๊ฐ™์€ ๊ณณ์—์„œ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.
  • button : ์„œ๋ฒ„๋กœ ์ „์†ก์„ ์‹คํ–‰ํ•˜๋Š” submit๋ฒ„ํŠผ, reset ํ•˜๋Š” ๋ฒ„ํŠผ ๋“ฑ์ด ์žˆ์Šต๋‹ˆ๋‹ค.
  • fieldset/ legend : ์ž…๋ ฅ ํƒœ๊ทธ๋“ค์„ ๊ทธ๋ฃนํ™”ํ•  ๋•Œ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

 

๐ŸŸก 2. Input ํƒœ๊ทธ

- input ํƒœ๊ทธ๋Š” formํƒœ๊ทธ ์•ˆ์—์„œ ์‚ฌ์šฉ๋˜๋Š” ์ž…๋ ฅ ํƒœ๊ทธ ์ค‘์—์„œ ๊ฐ€์žฅ ์ค‘์š”ํ•˜๋ฉด์„œ ๋งŽ์ด ์‚ฌ์šฉ๋˜๋Š” ํƒœ๊ทธ์ž…๋‹ˆ๋‹ค. ๊ทธ๋ž˜์„œ ์ข…๋ฅ˜ ๋˜ํ•œ ๋งค์šฐ ๋‹ค์–‘ํ•ฉ๋‹ˆ๋‹ค. input ํƒœ๊ทธ์˜ ์ข…๋ฅ˜๋ฅผ ๋‹ค๋ฃจ๋Š” ๊ฒƒ์€ type ์†์„ฑ์„ ์ด์šฉํ•ด์„œ ๋‹ค๋ฃน๋‹ˆ๋‹ค. form ํƒœ๊ทธ ๋‚ด์— ์กด์žฌํ•ด์•ผ ์ž…๋ ฅ ๋ฐ์ดํ„ฐ๋ฅผ ์ „์†กํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์„œ๋ฒ„์— ์ „์†ก๋˜๋Š” ๋ฐ์ดํ„ฐ๋Š” name ์†์„ฑ์„ ํ‚ค๋กœ, value ์†์„ฑ์„ ๊ฐ’์œผ๋กœ ํ•˜์—ฌ key=value์˜ ํ˜•ํƒœ๋กœ ์ „์†ก์ด ๋ฉ๋‹ˆ๋‹ค.


๐ŸŸก 3. Input ํƒœ๊ทธ์˜ ์ข…๋ฅ˜

  ๐ŸŸฃ 3.1 button 

<!DOCTYPE html>
<html>
  <body>
    <form>
      <input type="button" value="click!" onclick="alert('click button!')">
    </form>
  </body>
</html>

button type์˜ ๋ชจ์Šต๊ณผ ํด๋ฆญ ํ›„ ์ด๋ฒคํŠธ ๋ฐœ์ƒ

   - button type์€ value ์†์„ฑ๊ณผ onclick ์†์„ฑ์„ ์ฃผ๋กœ ์‚ฌ์šฉํ•˜๊ณ , value ์†์„ฑ์€ ๋ฒ„ํŠผ์— ์–ด๋– ํ•œ ๊ธ€์ž๋ฅผ ๋ณด์—ฌ์ค„์ง€๋ฅผ ์„ค์ •ํ•˜๊ณ , onclick ์†์„ฑ์€ ๋ฒ„ํŠผ์„ ๋ˆŒ๋ €์„ ์‹œ ์–ด๋– ํ•œ ์ด๋ฒคํŠธ๋ฅผ ๋ฐœ์ƒ์‹œํ‚ฌ์ง€ ์„ค์ •ํ•˜๋Š” ์†์„ฑ์ž…๋‹ˆ๋‹ค.

 

 ๐ŸŸฃ 3.2 check box

<!DOCTYPE html>
<html>
  <body>
    <form>
      <input type="checkbox" name="check1" value="apple" checked> ์• ํ”Œ
      <input type="checkbox" name="check2" value="samsung"> ์‚ผ์„ฑ
      <input type="checkbox" name="check3" value="meta"> ๋ฉ”ํƒ€
    </form>
  </body>
</html>

checkbox type

   - checkbox type์€ name, value, checked ๋“ฑ๊ณผ ๊ฐ™์€ ์†์„ฑ์„ ๊ฐ€์ง€๋Š”๋ฐ, name์€ ๋ง ๊ทธ๋ž˜๋„ checkbox์˜ ์ด๋ฆ„์ด ๋˜๊ณ , value๋Š” checkbox์˜ ๊ฐ’์ด ๋ฉ๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  checked ์†์„ฑ์€ ์›น ํŽ˜์ด์ง€๋ฅผ ์—ด์—ˆ์„ ๋•Œ checkbox๊ฐ€ ์ฒดํฌ๋œ ์ƒํƒœ๋กœ ๋˜๋„๋ก ํ•˜๋Š” ์†์„œ์ž…๋‹ˆ๋‹ค.

 

  ๐ŸŸฃ 3.3 radio

<!DOCTYPE html>
<html>
  <body>
    <form>
      <input type="radio" name="radio1" value="apple" checked> ์• ํ”Œ
      <input type="radio" name="radio1" value="samsung"> ์‚ผ์„ฑ
      <input type="radio" name="radio1" value="meta"> ๋ฉ”ํƒ€
      <br>
      <input type="radio" name="radio2" value="apple" checked> ์• ํ”Œ
      <input type="radio" name="radio2" value="samsung"> ์‚ผ์„ฑ
      <input type="radio" name="radio3" value="meta"> ๋ฉ”ํƒ€
    </form>
  </body>
</html>

radio type&amp;nbsp;

   - radio type์€ ์—ฌ๋Ÿฌ ๊ฐœ์˜ ์„ ํƒ์ง€ ์ค‘์— ํ•˜๋‚˜๋ฅผ ์„ ํƒํ•˜๊ฒŒ ํ•  ๋•Œ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค. checkbox์™€ ๋™์ผํ•˜๊ฒŒ name, value, checked ์†์„ฑ์„ ๊ฐ–๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. ๋‹ค๋งŒ checkbox์™€ ๋‹ค๋ฅธ ์ ์€ ๊ฐ™์€ ๋ฌถ์Œ์˜ radio๋Š” name์ด ๊ฐ™์•„์•ผ ํ•ฉ๋‹ˆ๋‹ค. name์ด ๋‹ฌ๋ผ์ง€๋ฉด ๋‹ค๋ฅธ radio ๋ฌถ์Œ์œผ๋กœ ์ธ์‹ํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. ์œ„์— ์‚ฌ์ง„์„ ๋ณด๋ฉด ๊ฐ™์€ name์œผ๋กœ ๋œ '์• ํ”Œ'์—์„œ '์‚ผ์„ฑ'์„ ๋ˆŒ๋ €์„ ๋•Œ '์• ํ”Œ'์— ์žˆ๋˜ ์ฒดํฌ๊ฐ€ '์‚ผ์„ฑ'์œผ๋กœ ๊ฐ„ ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ ๋‹ค๋ฅธ name์„ ๊ฐ€์ง„ radio์„ ๋ˆŒ๋ €์„ ๋•Œ๋Š” ๋ฐ˜์‘ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. 

 

  ๐ŸŸฃ 3.4 color

  - color type์€ ์ƒ‰์ƒ์„ ์„ ํƒํ•˜์—ฌ ์ž…๋ ฅํ•  ๋•Œ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

<!DOCTYPE html>
<html>
  <body>
    <form>
      <input type='color' name='chooseColor'>
    </form>
  </body>
</html>

 

color type

 

  ๐ŸŸฃ 3.5 date

   - date type์€ ๋‚ ์งœ๋ฅผ ์ž…๋ ฅํ•  ๋•Œ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

<!DOCTYPE html>
<html>
  <body>
    <div>
    <form>
      <input type='date' name='date_select'>
    </form>
  </body>
</html>

date type

  - ๋‚ ์งœ๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” type์—๋Š” date, datetime, datetime-local, month, week์ด ์žˆ์Šต๋‹ˆ๋‹ค. (๊ฐ๊ฐ ์ƒ๊น€์ƒˆ์™€ value๊ฐ€ ๋‹ค๋ฅด๋‹ˆ ํ•œ ๋ฒˆ์”ฉ ํ•ด๋ณด์„ธ์š” ๐Ÿ˜Š)

 

  ๐ŸŸฃ 3.6 file

    - file type์€ ํŒŒ์ผ์„ ์ฒจ๋ถ€ํ•  ๋•Œ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

<!DOCTYPE html>
<html>
  <body>
    <div>
    <form>
      <input type='file' name='addFile'>
    </form>
  </body>
</html>

file type

 

 

  ๐ŸŸฃ 3.7 time

   - time type์€ ์‹œ๊ฐ„์„ ์ž…๋ ฅํ•  ๋•Œ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

<!DOCTYPE html>
<html>
  <body>
    <div>
    <form>
      <input type='time' name='timeSelect'>
    </form>
  </body>
</html>

time type

 

 

  ๐ŸŸฃ 3.8 number

    - number type์€ ์ˆซ์ž๋งŒ ์ž…๋ ฅ๋ฐ›๊ณ  ์‹ถ์„ ๋•Œ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

<!DOCTYPE html>
<html>
  <body>
    <div>
    <form>
      <input type='number' name='numberInput' min="1" max="10" step="3" value="2">
    </form>
  </body>
</html>

number type

 - number type์€ min, max, step, value ์†์„ฑ์„ ๊ฐ€์ง€๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

์†์„ฑ ์„ค๋ช…
min ์„ ํƒํ•  ์ˆ˜ ์žˆ๋Š” ์ˆซ์ž์˜ ์ตœ์†Œ๊ฐ’์„ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.
max ์„ ํƒํ•  ์ˆ˜ ์žˆ๋Š” ์ˆซ์ž์˜ ์ตœ๋Œ€๊ฐ’์„ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.
step ๋ช‡์”ฉ ์ฆ๊ฐ€ํ• ์ง€ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค ex) min = "1" step ="2" ์ธ๊ฒฝ์šฐ 1 -> 3 -> 5 -> 7 ์‹์œผ๋กœ ์ฆ๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.
value ๊ธฐ๋ณธ๊ฐ’์„ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.

 

 

  ๐ŸŸฃ 3.9 range

   - range type์€ ๋ฒ”์œ„ ์„ค์ •ํ•˜์—ฌ ์ž…๋ ฅ์„ ๋ฐ›์„ ๋•Œ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

<!DOCTYPE html>
<html>
  <body>
    <div>
    <form>
      <input type='range' name='rangeChoose' min="1" max="100" step="2" value="10">
    </form>
  </body>
</html>

range type

 - range type๋„ number type๊ณผ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ min, max, step, value์ด ์†์„ฑ์„ ๊ฐ€์ง€๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. (์„ค๋ช…์€ nuber ์ฐธ์กฐ)

 

 

  ๐ŸŸฃ 3.10 password

    - password๋Š” ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅ๋ฐ›์„ ๋•Œ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

<!DOCTYPE html>
<html>
  <body>
    <div>
    <form>
      <input type='password' name='pw'>
    </form>
  </body>
</html>

   

password type

 

 

  ๐ŸŸฃ 3.11 ๊ทธ ์™ธ type

    - ์œ„์—์„œ ์„ค๋ช…ํ•œ type ์ด์™ธ์—๋„ email, hidden, image, reset, search, submit, tel, text, url ๋“ฑ ๋‹ค์–‘ํ•œ type์ด ์žˆ์Šต๋‹ˆ๋‹ค. ํŠนํžˆ email, hidden, tel ๋“ฑ์€ ์›น ๊ฐœ๋ฐœ ์‹œ ์ž์ฃผ ์‚ฌ์šฉํ•˜๋Š” type์ด๋ฏ€๋กœ ํ•œ ๋ฒˆ์”ฉ ์ฐพ์•„๋ณด์‹œ๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค! (์ž์„ธํ•˜๊ฒŒ ์„ค๋ช…์„ ์•ˆ ํ•œ ์ด์œ ๋Š” ๋ชจ์–‘์ƒˆ๊ฐ€ ๋น„์Šทํ•œ ๊ฒƒ๋“ค๋„ ์žˆ๊ณ , ์‹ค์ œ๋กœ ์‚ฌ์šฉ์„ ํ•ด๋ด์•ผ ์ฐจ์ด๋ฅผ ์•„๋Š” ๊ฒƒ๋“ค์ด๊ธฐ ๋•Œ๋ฌธ์— ์ž์„ธํ•˜๊ฒŒ ์„ค๋ช…์„ ์•ˆ ํ–ˆ์Šต๋‹ˆ๋‹ค. ์ ˆ๋Œ€ ๊ท€์ฐฎ์•„์„œ๊ฐ€ ์•„๋‹ˆ์—์š”! ใ…Žใ…Ž)

 

๐Ÿ“ ์ •๋ฆฌ

  • input ํƒœ๊ทธ๋Š” form ํƒœ๊ทธ ์•ˆ์—์„œ ์‚ฌ์šฉ๋˜๊ณ , ์ œ์ผ ๋งŽ์ด ์‚ฌ์šฉ
  • input ํƒœ๊ทธ๋Š” type์œผ๋กœ ์ข…๋ฅ˜๋ฅผ ๋ฐ”๊พธ๋Š”๋ฐ, ๊ต‰์žฅํžˆ ๋งŽ์€ ์ข…๋ฅ˜๊ฐ€ ์žˆ๋‹ค.

 

๊ธด ๊ธ€ ์ฝ์–ด์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค :) 
ํ‹€๋ฆฐ ๋‚ด์šฉ์ด ์žˆ๊ฑฐ๋‚˜, ๋ง๋ถ™์ผ ๋‚ด์šฉ์ด ์žˆ๋‹ค๋ฉด ์–ธ์ œ๋“ ์ง€ ๋Œ“๊ธ€ ๋‹ฌ์•„์ฃผ์„ธ์š”!
์ œ ๊ธ€์ด ์กฐ๊ธˆ์ด๋‚˜๋งˆ ์ฝ์€ ์‹  ๋ถ„๋“ค์—๊ฒŒ ๋„์›€์ด ๋˜๋„๋ก ๋…ธ๋ ฅํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค
๋‹ค์Œ ํŽธ์— ๋ดฌ์š”~

728x90
๋ฐ˜์‘ํ˜•