JavaScript

[JavaScript] 라디오 버튼 클릭 시 페이지 이동 간단 구현

효니님 2023. 7. 7. 16:04
728x90

url 리다이렉트(Redirect), location.href 와 location.replace 차이점

 

라디오 버튼 클릭 시 페이지 이동하기

html파일 두개를 만들어 두고 라디오 버튼 클릭 시 이동하는 방법을 구현해 보았다.

onClick = "window.location.href='링크'";
<li>
  <div class="rdo-group">
    <input
      type="radio"
      name="rdovisible"
      id="rdoShow"
      checked="checked"
      onClick="window.location.href='page1_list.html'"
    />
    <label for="rdoShow">
      <span class="rdo">page1</span>
    </label>
  </div>
  <div class="rdo-group">
    <input
      type="radio"
      name="rdovisible"
      id="rdoHide"
      onClick="window.location.href='page2_list.html'"
    />
    <label for="rdoHide">
      <span class="rdo">page2</span>
    </label>
  </div>
</li>


라디오 버튼 두 개를 만들어 두고 처음 선택되어 보일 부분은 checked 속성을 넣어준다.
페이지 이동 시 활성화되어 있는 페이지도 동일하게 적용해 주면 된다.

728x90