본문 바로가기

UI/Javascript

[Javascript] function and ( ) =>{ }

 

비교 연습해보기

onClick

<body>
  <input type="text" class="input">
  <button type="button" class="button" onclick="getInput()" >조회</button>
</body>

<script>
  function getInput () {
    const $input = document.querySelector(".input");
   const  inputValue = $input.value
}
</script>

 

() => { }

<body>
  <input type="text" class="input">
  <button type="button" class="button">조회</button>
</body>

<script>
  const $input = document.querySelector(".input");
  const $button = document.querySelector(".button");
  $input.addEventListener("click", ()=>{
    const buttonValue = $button.value
  }
</script>