[Javascript] window 하위 객체 location 객체 실습

Gammi·2022년 10월 6일
0

JS

목록 보기
10/22
post-thumbnail

장바구니 페이지와 결제 페이지로 이동하기

<!DOCTYPE html>
<html>
<head>
<title></title>
<script type="text/javascript">
  func(target) {
  // 파라미터 변수 설정 
  // 자바스크립트는 데이터 타입 적지 않음
  	if(target == "cart") {
      location.href = "test_cart.html";
      // 장바구니 페이지로 이동
    } else if(target == "order") {
      location.href = "test_order.html";
      // 구매 페이지로 이동
    loaction.href = "test_" + target + ".html";
    // if문을 쓰지 않고도 이동 가능
    // 둘 중에 아무거나 쓰면 됨
    }
  }
</script>
</head>
<body>
  <input type="button" value="장바구니 담기" onclick="func('cart')"><br>
    // 장바구니 버튼 생성
    // 큰 따옴표 내에서 또 큰 따옴표를 사용할 수 없기 때문에
    // func1 안에 작은 따옴표로 cart를 감쌌음
  <input type="button" value="즉시구매" onclick="func('order')">
   // 즉시구매 버튼 생성 
</body>
</html>
profile
개발자가 되었어요⭐️

0개의 댓글