View

<form>안에 <button>태그가 있는 경우에는

<button>클릭시 기본적으로 페이지가 reload된다.

 

이를 막기 위해서는 아래와 같이

자바스크립트로 preventDefault 로 기본동작을 막을 수 있다.

 

버튼.addEventListener('click', function(e)) {

e.preventDefault();

});

 

혹은 

button 태그에 type속성을 button으로 주면 페이지가 새로고침되지 않는다.

<button type="button">

 

https://stackoverflow.com/questions/1878264/how-do-i-make-an-html-button-not-reload-the-page

Share Link
reply
«   2025/02   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28