JavaScript

Form 접근하기

Hyunsoo_Kim 2023. 8. 24. 01:31
<!DOCTYPE html>
<html lang="ko">
<head>
  <meta charset="UTF-8">
  <title>evantHandler</title>
  <link rel="stylesheet" href="eventHandler.css">
  <script src="eventHandler.js"></script>
</head>
<body>
    <div id="wrapper">
      <form name="formBox">
        <input name="inputOne">
        <input name="inputTwo">
        <button name='btn'>BUTTON</button>
      </form>
    </div>
</body>
</html>

위 코드를 전제로,

window.onload=function(){
    console.log(document.forms);
}
//[form, formBox: form] //HTMLCollection

 

window.onload=function(){
    console.log(document.formBox);
}
//<form name="formBox">...</form> //HTMLFormElement

 

window.onload=function(){
    for(let i of document.formBox){
        console.log(i); 
    }
}
/*
<input name="inputOne">
<input name="inputTwo">
<button name="btn">BUTTON</button>
*/