๐Ÿ‘ฉ๐Ÿผโ€๐Ÿ’ป๋ฐ”๋‹๋ผ JS๋กœ ํฌ๋กฌ ์•ฑ ๋งŒ๋“ค๊ธฐ : #4.0-4.2

change upยท2023๋…„ 6์›” 7์ผ
2
post-custom-banner
Momentum log In
#4.0-4.2 Login form์ž‘์„ฑ
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel = "stylesheet" href="app.css">
    <title>Momentum</title>
</head>
<body>
    <form id="login-form">
  <input 
    required
    maxlength = "15"
    type ="text" 
    placeholder="what is your name?"/> 
    <button>log In</button> 
    </div>
</body>
<script src = "app.js"></script>
</html>
<!--input์˜ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ๋ฅผ ์œ„ํ•ดform ์‚ฌ์šฉ / alret๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š์•„๋„ ์ž…๋ ฅ๊ฐ’์ด ์—†์œผ๋ฉด ๊ฒฝ๊ณ 
but formt์‚ฌ์šฉ์‹œ ์›น์‚ฌ์ดํŠธ๊ฐ€ ์ƒˆ๋กœ๊ณ ์นจ๋˜๋ฏ€๋กœ ์ƒˆ๋กœ๊ณ ์นจ ๋ฐฉ์ง€์ฝ”๋“œ๋ฅผ ๋„ฃ์–ด์ค˜์•ผํ•จ. -->
<!--input ์—๋Š” ๋‹ค์–‘ํ•œ ํผ์„ ๋„ฃ์„์ˆ˜๊ฐ€ ์žˆ๊ณ  required๋Š” ํ•„์ˆ˜์š”์†Œ / maxlength๋Š” ๊ธ€์ž์˜ ์ตœ๋Œ€์ˆ˜ ์ œํ•œ-->

const loginInput = document.querySelector("#login-form input");
const loginForm = document.querySelector("#login-form")
//document๋˜๋Š” ํ•˜๋‚˜์˜ element(div id ='login-form' )๋ฅผ ํ†ตํ•ด์„œ ๊ฒ€์ƒ‰์ด ๊ฐ€๋Šฅํ•˜๋‹ค.
loginbutton.addEventListener("click" , onLoginBtnClick)
//input์˜ ๋‚ด์šฉ์„ ๊ฐ€์ ธ์˜ค๋ ค๋ฉด value property๋ฅผ ์ฐพ์•„๋ด์•ผํ•œ๋‹ค.
function onLoginSubmit(e) {
e.preventDefault();//๋ธŒ๋ผ์šฐ์ €๊ฐ€ ๊ธฐ๋ณธ๋™์ž‘์„ ํ•˜์ง€์•Š๋„๋ก ๋ง‰์•„์คŒ
  console.log(loginInput.value);
  }



loginForm.addEventListener("submit",onLoginSubmit)
//submit์€ ์ž…๋ ฅ๊ฐ’์„ ๋ฐ›์„ ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์ค€๋‹ค.
profile
์ƒˆ์‹น์ด
post-custom-banner

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