버튼 클릭시마다 새로고침되게 하려면 어떻게 해야하나요?

버튼 클릭시마다 새로고침되게 하려면 어떻게 해야하나요?

QA

버튼 클릭시마다 새로고침되게 하려면 어떻게 해야하나요?

본문

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
/* Style the buttons */
.btn {
  border: none;
  outline: none;
  padding: 10px 16px;
  background-color: #f1f1f1;
  cursor: pointer;
  font-size: 18px;
}

/* Style the active class, and buttons on mouse-over */
.active, .btn:hover {
  background-color: #666;
  color: white;
}
</style>
</head>
<body>

<h1>Active Button</h1>
<p>Highlight the active/current (pressed) button.</p>
  
<div id="myDIV">
  <button class="btn">1</button>
  <button class="btn active">2</button>
  <button class="btn">3</button>
  <button class="btn">4</button>
  <button class="btn">5</button>
</div>

<script>
// Add active class to the current button (highlight it)
var header = document.getElementById("myDIV");
var btns = header.getElementsByClassName("btn");
for (var i = 0; i < btns.length; i++) {
  btns[i].addEventListener("click", function() {
  var current = document.getElementsByClassName("active");
  current[0].className = current[0].className.replace(" active", "");
  this.className += " active";
  });
}
</script>

</body>
</html>

 

여기서 버튼 클릭시마다 새로고침이 되게 하고 싶어요

이 질문에 댓글 쓰기 :

답변 1

버튼에 onclick 이벤트 넣어주시면됩니다

onClick="window.location.reload()"

 

스크립트로 추가한 버튼은 무조건 새로고침하면 없어지게 됩니다
ajax로 페이지내용을 그대로 복사해서 추가된버튼만 남기고 나머지는 삭제하도록 새로만드는게 아니라면 불가능해보이네요

답변을 작성하시기 전에 로그인 해주세요.
전체 169
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT