๐Ÿ’งHTML:Form and Table

hojuneยท2023๋…„ 8์›” 13์ผ
0

Web Development

๋ชฉ๋ก ๋ณด๊ธฐ
4/33

Tables

<table>

<td> table data cell or table data

<tr> table row

<th> table head
  
  
<thead>

<tbody>

<tfoot>

์œ„ 3๊ฐ€์ง€๋Š” ์ฝ”๋“œ ์† ์ ‘๊ทผ์„ฑ, ๊ฐ€๋…์„ฑ
  
  
rowspan

colspan

ํ—ค๋”๋ฅผ 2ํ–‰์œผ๋กœ ๋งŒ๋“ค ๋•Œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Œ

Table ์‚ฌ์šฉ ์˜ˆ์‹œ

<body>

    <table>

        <thead>

            <tr>

                <th rowspan="2">Subscription</th>

                <th colspan="2">Price</th>

                <th rowspan="2">Support</th>

            </tr>

            <tr>

                <th>member</th>

                <th>non member</th>

            </tr>

        </thead>

        <tbody>

            <tr>

                <td>Free</td>

                <td>Free</td>

                <td>Free</td>

                <td>N/A</td>

            </tr>

            <tr>

                <td>Personal</td>

                <td>$4.99</td>

                <td>$9.99</td>

                <td>Weekdays</td>

            </tr>

            <tr>

                <td>Business</td>

                <td>$29.99</td>

                <td>$49.99</td>

                <td>24/7</td>

            </tr>

        </tbody>

    </table>

</body>

์•„๋ž˜ ๊ฒฐ๊ณผ๋ฌผ

๋ถ€๊ฐ€์„ค๋ช…

<th>์—์„œ price๋ฅผ ๋‘๊ฐœ๋กœ ๋ถ„๋ฅ˜ํ•˜๊ณ  ์‹ถ์–ด์„œ rowspan์„ ์‚ฌ์šฉํ•ด ๋‚˜๋จธ์ง€ ๋‘ ํ•ญ๋ชฉ์ธ sub์™€ sup์„ 
2ํ–‰ ํฌ๊ธฐ๋งŒํผ ์ฐจ์ง€ํ•˜๊ฒŒ ๋งŒ๋“ ๋’ค์— colspan์„ ์‚ฌ์šฉํ•ด price์—๋Š” 2๊ฐœ ์—ด ๋งŒํผ์˜ ํฌ๊ธฐ๊ฐ€ ๋“ค์–ด๊ฐˆ 
์ˆ˜ ์žˆ๊ฒŒ๋” ํ•œ ๊ฒƒ์ด๋‹ค.

Forms

<input> ์ผ๋ฐ˜์ ์ธ ์ž…๋ ฅ ํ˜•์‹ (๋‹ซ๋Š” ํƒœ๊ทธ๊ฐ€ ์—†์Œ)

<input ~~~~~~~>

Type - text, password, color, time, etc..


Placeholder = ์ž…๋ ฅ๋ž€์˜ ์ž„์‹œ ํ…์ŠคํŠธ๋ฅผ ์ง€์ •ํ•˜๋Š” ์†์„ฑ


<form action="/tacos">

    <input type="text" placeholder="User Name">

    <input type="password" placeholder="PassWord">

    <input type="color">

    <input type="time">

</form>



<label> 

   <p>

       <label for="username">Enter a Username:</label>

       <input id="username" type="text" placeholder="User Name">

   </p>

   <p>

        <label for="password">Enter a Password:</label>

        <input id="password" type="password" placeholder="PassWord">

   </p>

   <p>

         <label for="color">choise a color</label>

         <input id="color" type="color">

   </p>


<label> ์•ˆ์— ์žˆ๋Š” for = "A"์™€ <input>์•ˆ์— ์žˆ๋Š” id = "A"๋ฅผ A์ฒ˜๋Ÿผ 
        ๊ฐ™์€ text๋กœ ์จ์ฃผ๋ฉด ์—ฐ๊ฒฐ ์‹œ์ผœ์ค„ ์ˆ˜ ์žˆ์Œ


   <label>

        Enter a Number:

       <input type="Number" placeholder="enter a number">

   </label>

       ์ด๋ ‡๊ฒŒ ์‚ฌ์šฉํ•ด๋„ ์—ฐ๊ฒฐ์‹œํ‚ฌ ์ˆ˜ ์žˆ๋‹ค.


  
<button> js์™€ ํ•จ๊ป˜ ๋งŽ์ด ์“ฐ์ž„


ํผ์•ˆ์— ์žˆ๋Š” ๋ฒ„ํŠผ๊ณผ ํผ๋ฐ–์— ์žˆ๋Š” ๋ฒ„ํŠผ์€ ์ž‘๋™์—์„œ์˜ ์ฐจ์ด๊ฐ€ ์žˆ๋‹ค.

ํผ์•ˆ์—์„œ๋ผ๋„ type์„ button์œผ๋กœ ์ง€์ •ํ•œ๋‹ค๋ฉด ์ œ์ถœ์˜ ๊ธฐ๋Šฅ์ด ์•„๋‹ˆ๋ผ 
  
๋‹จ์ˆœํ•œ ๋ฒ„ํŠผ์œผ๋กœ์„œ ๊ธฐ๋Šฅํ•  ์ˆ˜ ์žˆ๋‹ค.

+) button์€ label์„ ์—ฐ๊ฒฐํ•˜์ง€ ์•Š๋Š”๋‹ค ์ถฉ๋Œ์ด ์ƒ๊ธธ ์ˆ˜ ์žˆ๋‹ค  



name ์†์„ฑ

input์•ˆ์—์„œ ์“ฐ์ด๋ฉฐ ๋ฐ์ดํ„ฐ๋ฅผ ์ „์†กํ•  ๋•Œ ์ด์šฉํ•  ๋ถ€๋ถ„์€ 
  
ํ•ด๋‹น์ด๋ฆ„์œผ๋กœ ๋ ˆ์ด๋ธ”๋ง ๋˜์–ด์žˆ์Œ (์ค‘์š”!)

์„œ๋ฒ„๋กœ ๋ฐ์ดํ„ฐ๋ฅผ ์ „์†กํ• ๋•Œ ์‚ฌ์šฉ



<label for="username">Enter a Username:</label>

<input id="username" type="text" placeholder="User Name" name="username">



<form>ํ™œ์šฉ



<form action="https://www.youtube.com/results">
  
   <input type="text" name="search_query">

   <button>Search Youtube</button>

</form>


๋ฒ„ํŠผ์„ ๋งŒ๋“ค์–ด์„œ action์— ์žˆ๋Š” ์ฃผ์†Œ์— ๋”ฐ๋ผ ์œ ํŠœ๋ธŒ ๊ฒ€์ƒ‰์„ ํ•˜๊ฒŒ ๋จ
  

Important Input Types


input type - checkbox


<form action="/birds">

      <input type="checkbox" name="agree_tos" id="agree">

      <label for="agree">i agree to everything</label>

      <button>Submit</button>
  
 </form>



 input type - radio
  

 <label for="xs">xs:</label>

 <input type="radio" name="size" id="xs" value="xsmall">
  

 <label for="s">s:</label>

 <input type="radio" name="size" id="s" value="small">
  

 <label for="m">m:</label>

 <input type="radio" name="size" id="m" value="medium">



value ๊ฐ’์ด ์„œ๋ฒ„์— ๋„˜๊ฒจ์ฃผ๋Š” ๊ฐ’์ด ๋˜๋Š” ๊ฒƒ
  

 

Checkbox and Radio Difference?

์ „์ž๋Š” ์ฒดํฌ๋ฐ•์Šค๊ฐ€ 2๊ฐœ๋ผ๊ณ  ๊ฐ€์ •ํ–ˆ์„ ๋•Œ 2๊ฐœ ๋ชจ๋‘ ์„ ํƒํ•˜๊ฑฐ๋‚˜ ํ•˜์ง€ ์•Š๊ฑฐ๋‚˜ ์ƒ๊ด€์—†์Œ

ํ›„์ž๋Š” ์ฒดํฌ๋ฐ•์Šค๊ฐ€ 3๊ฐœ๋ผ๊ณ  ๊ฐ€์ •ํ–ˆ์„ ๋•Œ 3๊ฐœ ์ค‘ ๋‹จ ํ•œ๊ฐœ๋งŒ ์„ ํƒ ๋˜์–ด์•ผ ํ•จ



name๊ฐ’์ด size๋กœ ํ†ต์ผ๋˜์–ด ์žˆ๋Š”๋ฐ ์ด๋ ‡๊ฒŒ ํ•ด์•ผ ๊ฐ๊ฐ์˜ ๊ฒƒ๋“ค์ด ํ•˜๋‚˜๋กœ ์—ฐ๊ฒฐ์ด ๋จ




<select> ๊ณผ ํ•˜์œ„ ๋ชฉ๋ก์ธ <option>

  
<label for="meal">please select an entree</label>

<select name="meal" id="meal">

       <option value="">--please select--</option>

       <option value="fish">Fish</option>

       <option value="veg" selected>Veg</option>

       <option value="steak">Steak</option>

</select>



์ฒซ๋ฒˆ์งธ ์˜ต์…˜์ฒ˜๋Ÿผ value๋ฅผ ๋น„์›Œ๋†“๊ณ  text๋งŒ ๋„ฃ์„ ์ˆ˜๋„ ์žˆ๋‹ค.
  

๋˜ํ•œ selected์ฒ˜๋Ÿผ ๋งจ์œ„์˜ ๊ฐ’์ด ์•„๋‹Œ ๋‹ค๋ฅธ ๊ฐ’์„ ์ž๋™์œผ๋กœ ์„ ํƒ๋˜๋„๋ก ํ•  ์ˆ˜ ์žˆ๋‹ค.

  
  

input type - range


<label for="range">amount of cheese</label>

<input type="range" id="range" min="1" max="99" step=4"name="cheese level">


min max ๊ฐ’๊ณผ step์€ ํ•œ์นธ๋‹น ์–ผ๋งˆ์”ฉ ์˜ค๋ฅด๋‚ด๋ฆด์ง€ ์ •ํ•  ์ˆ˜ ์žˆ๋‹ค.



<textarea>


  <label for="request">any request</label>

  <br>

  <textarea name="request_server" id="request" cols="30" rows="10" 
  placeholder="something"></textarea>

Input ์š”์†Œ์— Label์„ ์—ฐ๊ฒฐํ•˜๋Š” ์ด์œ ?

์—ฌ๋Ÿฌ ์žฅ์ ์ด ์žˆ๋‹ค

๋ ˆ์ด๋ธ” ํ…์ŠคํŠธ๋Š” ์‹œ๊ฐ์ ์œผ๋กœ๋งŒ ์ปจํŠธ๋กค์— ์—ฐ๊ฒฐ๋œ ๊ฒƒ์ด ์•„๋‹ˆ๋ผ, ํ”„๋กœ๊ทธ๋žจ ์ƒ์—์„œ๋„ ์—ฐ๊ฒฐ๋œ๋‹ค
์ด ๋ง์€ ๋ณด์กฐ ๊ธฐ์ˆ  ์—ญ์‹œ ์–ด๋–ค ์ปจํŠธ๋กค์˜ ์„ค๋ช…์ด ์ •ํ™•ํžˆ ๋ฌด์—‡์ธ์ง€ ์•Œ ์ˆ˜ ์žˆ๋‹ค๋Š” ๊ฒƒ์ด๋ฏ€๋กœ, 
์‚ฌ์šฉ์ž๊ฐ€ ์–‘์‹ ์ž…๋ ฅ ์นธ์— ํฌ์ปค์Šค๋ฅผ ํ•œ ๊ฒฝ์šฐ, ์Šคํฌ๋ฆฐ ๋ฆฌ๋”๊ฐ€ ๊ทธ ์นธ์— ๋Œ€ํ•œ ์˜ฌ๋ฐ”๋ฅธ ์„ค๋ช…์„ 
์ฝ์–ด์ค„ ์ˆ˜ ์žˆ์–ด์„œ ์‚ฌ์šฉ์ž๊ฐ€ ์–ด๋–ค ๋ฐ์ดํ„ฐ๋ฅผ ์ž…๋ ฅํ•ด์•ผ ํ•˜๋Š”์ง€ ์ดํ•ดํ•˜๊ธฐ๊ฐ€ ์‰ฌ์›Œ์ง„๋‹ค

๋ ˆ์ด๋ธ”์„ ํด๋ฆญํ•˜๊ฑฐ๋‚˜ ํ„ฐ์น˜ํ•˜๋Š” ๊ฒฝ์šฐ, ๋ธŒ๋ผ์šฐ์ €๋Š” ๋ ˆ์ด๋ธ”์ด ์—ฐ๊ฒฐ๋œ ์š”์†Œ๋กœ ํฌ์ปค์Šค๋ฅผ ์ „๋‹ฌํ•œ๋‹ค

+) <label>์„ <input>๊ณผ ์—ฐ๊ฒฐํ•˜๋ ค๋ฉด ์šฐ์„  <input>์— id ํŠน์„ฑ์„ ์ง€์ •ํ•ด์•ผ ํ•œ๋‹ค
   <label>์—๋Š” for ํŠน์„ฑ์— ๊ทธ id์™€ ๋™์ผํ•œ ๊ฐ’์„ ์ง€์ •ํ•œ๋‹ค
   ๋˜๋Š”, <input>์„ <label>์˜ ์•ˆ์— ๋ฐฐ์น˜ํ•˜๋Š” ๋ฐฉ๋ฒ•๋„ ์žˆ๋‹ค 
   ์ด ๋•Œ๋Š” ์•”์‹œ์ ์œผ๋กœ ์„œ๋กœ์˜ ๊ด€๊ณ„๋ฅผ ์ƒ์„ฑํ•˜๋ฏ€๋กœ id์™€ for ํŠน์„ฑ์„ ์ง€์ •ํ•  ํ•„์š”๋Š” ์—†๋‹ค

HTML5 ํผ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ


Html attribute - input - required


<label for="first">Enter First Name</label>

<input type="text" name="first" id="first" required>


  <p>

    <label for="username">Username</label>

    <input type="text" name="username" id="username" 
           minlength="5" maxlength="20" required>

  </p>



required = ์ž…๋ ฅ๊ฐ’์ด ์—†์œผ๋ฉด ์ œ์ถœ์ด ์•ˆ๋จ 


minlength, maxlength = ์œ„์˜ range์˜ min๊ณผ max์™€ ๊ตฌ๋ณ„๋˜๊ฒŒ ์•Œ์•„ ๋‘˜ ๊ฒƒ

๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ์ถฉ์กฑํ•˜์ง€ ๋ชปํ•  ์‹œ ์ œ์ถœ์ด ์•ˆ๋จ

0๊ฐœ์˜ ๋Œ“๊ธ€