
<form id="form1">
<p>form1</p>
<input type="text">
</form>
<form class="form2">
<p>form2</p>
<input type="text">
</form>
<form name="form3">
<p>form3</p>
<input type="text">
</form>
๐ฝconsole
<form name="frm1">
<label for="uname">์ด๋ฆ</label>
<input type="text" id="uname" name="uname">
<label for="age">๋์ด</label>
<input type="text" id="age" name="age">
<label for="gender">์ฑ๋ณ</label>
<select id="gender" name="gender">
<option value="male">male</option>
<option value="female">female</option>
</select>
<button type="submit">์ ์ก</button>
</form>
๐ฝconsole
ํ ์ค ์ ๋ ฅ ์์(or ์ฌ๋ฌ ์ค ์ ๋ ฅ ์์)
- value ์์ฑ ์ฐธ์กฐ : ์ ๋ ฅํ ๊ฐ์ ๊ฐ์ ธ์ค๊ธฐ
- value ์์ฑ์ ๊ฐ ํ ๋น : ์๋ก์ด ๊ฐ์ ์ค์
์ฒดํฌ๋ฐ์ค ์์ or ๋ผ๋์ค๋ฒํผ ์์
- checked ์์ฑ : ์ฒดํฌ ๋๋ ์ ํ ์ํ๋ฅผ ํ์ธ(์ ํ๋์ด์์ผ๋ฉด true๋ฅผ, ์๋๋ฉด false๋ฅผ ๋ฐํ)
- checked ์์ฑ์ true ํ ๋น : ์ฒดํฌ ๋๋ ์ ํ ์ํ๋ฅผ ๊ธฐ๋ณธ์ผ๋ก ์ค์
<div> <input class="bab" type="checkbox" value="morn">์์นจ <input class="bab" type="checkbox" value="lunc">์ ์ฌ <input class="bab" type="checkbox" value="denn">์ ๋ </div>//๋ธ๋ผ์ฐ์ ์์ ์์นจ, ์ ์ฌ๋ง ์ฒดํฌํด๋ ์ํ.
//โ์ฒดํฌ๋ฐ์ค ์ ๋ ์ ํด๋นํ๋ 2์ธ๋ฑ์ค๋ง false๋ฅผ ๋ฐํ. true๋ฅผ ํ ๋นํด์ ์ฒดํฌ ์ํ๋ก ๋ณ๊ฒฝํ ์ ์๋ค.
๐ฌradio๋ฒํผ : ์ฌ๋ฌ radio ํ์ ์ด ๊ฐ์ name์ ๊ฐ์ง ๋๋ ๊ทธ ์ค ํ๋๋ง ์ ํํ ์ ์๋ค.<div> <input type="radio" value="S" name="size">์ <input type="radio" value="M" name="size">์ค <input type="radio" value="L" name="size">๋ <button type="button" onclick="sizeCheck()">์ ํํ ์ฌ์ด์ฆํ์ธ</button> </div><script> function sizeCheck(){ const radios = document.querySelectorAll('input[type="radio"]'); for(let i=0; i<radios.length; i++){ if(radios[i].checked == true){ console.log(radios[i].value); } } } </script>![]()
์ฝค๋ณด๋ฐ์ค ์์
<div> <select id="memory"> <option value="4">4GB</option> <option value="8">8GB</option> <option value="16">16GB</option> <option value="32">32GB</option> </select> </div>//๋ธ๋ผ์ฐ์ ์์ 8GB๋ฅผ ์ ํํด ๋ ์ํ
//โ8GB์ ํด๋นํ๋ 1์ธ๋ฑ์ค๋ง true๋ฅผ ๋ฐํ
๐ฅ์ฐ์ต๋ฌธ์ -๋ฒํผ์ ๋๋ฅด๋ฉด ํด๋น ์ํ๋ก ๋ณ๊ฒฝํ๊ธฐ
<body>
<div class="container">
<div id="main">
<p id="p1">p1 ํ
์คํธ</p>
<p id="p2">p2 ํ
์คํธ</p>
</div>
</div>
<button onclick="changeMain()">main ๋ฐฐ๊ฒฝ์ gray๋ก ๋ณ๊ฒฝ</button>
<button onclick="changeP1()">p1 ๊ธ์์ red๋ก ๋ณ๊ฒฝ</button>
<button onclick="changeP2()">"p2 ํ
์คํธ"๋ฅผ "p2 ๊ธ์" ๋ก ๋ณ๊ฒฝ</button>
<script>
function changeMain(){
document.querySelector('#main').style.backgroundColor = 'gray';
}
function changeP1(){
document.querySelector('#p1').style.color = 'red';
}
function changeP2(){
document.querySelector('#p2').innerText = 'p2 ๊ธ์';
}
</script>
</body>
๐ฝ์คํ ๊ฒฐ๊ณผ