>source

<input type="text" name="" id="num1" placeholder="number1">
<input type="text" name="" id="num2" placeholder="number2"> 
<button type="submit" id="add">Add</button>
<script>
let value1 = document.getElementById('num1');
let value2 = document.getElementById('num2'); 
let submit = document.getElementById('add').addEventListener('onclick', getValue);
function getValue(){
let newValue1 = value1.value;
let newValue2 = value2.value;
console.log(newValue1 + newalue2);
}
</script>

  • 답변 # 1

    addEventListener('onclick', getValue) 업데이트해야합니다 addEventListener('click', getValue)

    let value1 = document.getElementById('num1');
    let value2 = document.getElementById("num2");
    document.getElementById("add").addEventListener('click', getValue);
    function getValue() {
      let newValue1 = value1.value;
      let newValue2 = value2.value;
      console.log(newValue1 + newValue2);
    }
    
    

    <input type="text" name="" id="num1" placeholder="number1">
    <input type="text" name="" id="num2" placeholder="number2">
    <button id="add">Add</button>
    
    

    또는 사용 <button id="add" onclick="getValue()">Add</button> 없이 addEventListener

    let value1 = document.getElementById('num1');
    let value2 = document.getElementById("num2");
    function getValue() {
      let newValue1 = value1.value;
      let newValue2 = value2.value;
      console.log(newValue1 + newValue2);
    }
    
    

    <input type="text" name="" id="num1" placeholder="number1">
    <input type="text" name="" id="num2" placeholder="number2">
    <button id="add" onclick="getValue()">Add</button>
    
    

  • 이전 url rewriting - 대문자가있는 모든 URL과 일치하는 정규식 캡처 그룹
  • 다음 mongodb - $lookup 후 중첩 필드에서 $match가 작동하지 않는 이유