• 회원가입
  • 로그인

[DOM_Document] JS - getElementsByName() 메서드 ★ - 네임선택자

document.getElementsByName() 예제

 

site: <input name="hz" type="text" value="홈짱닷컴"></br>

host: <input name="hz" type="text" value="Homzzang.com"></br>


<button onclick="homzzang()">클릭</button>


<p id="demo"></p>


<script>

function homzzang() {

  var x = document.getElementsByName("hz")[0].tagName;

  document.getElementById("demo").innerHTML = x;

}

</script>

 

결과보기

 

 

document.getElementsByName() 예제

 

<input type="text" class="a" name="a" onkeyup="homzzang()"> 

<input type="text" class="b" name="b" onkeyup="homzzang()">

<textarea name="c" rows="8" cols="80"></textarea>

 

<script>

function homzzang() {

    var a = document.getElementsByName('a')[0].value;

    var b = document.getElementsByName('b')[0].value;

    var res = a + "\n" + b;

    document.getElementsByName('c')[0].value = res;

}

</script>

 

eyekiss 님 (190918) https://sir.kr/qa/323741


방문 감사합니다. (즐겨찾기 등록: Ctrl + D)

찾아주셔서 감사합니다. Since 2012