<!-- 아래의 요구사항을 반영하는 화면을 구현하는 코드이다. 하지만 화면 처럼 결과를 얻지 못했다.
    요구사항과 화면이 다른 원인과 조치사항을 작성하시오.
*  탭 메뉴 선택하기
   1. 이 문서를 처음 로드하면 런던탭의 색상이 #ccc로 표시된다.
   2. 런던으르 선택하면 id="London"의 내용이 나타난다.
   3. 다른 탭을 선택하면 이전에 선택한 내용은 사라지고 선택한 내용 1가지만 나타난다.
   4. 구현된 화면 이미지와 같이 선택한 탭만 버튼 색상을 '#ccc'로 설정한다.
* 구현된 화면 -->
<!-- @page { margin: 2cm } P { margin-bottom: 0.21cm } -->

<!DOCTYPE html>

<html>

<head>

<style>

body {

font-family: Arial;

}

 

.tab {

overflow: hidden;

border: 1px solid #ccc;

background-color: #f1f1f1;

}

 

.tab button {

float: left;

border: none;

outline: none;

cursor: pointer;

padding: 14px 16px;

font-size: 17px;

}

 

.tab button:hover {

background-color: #ddd;

}

 

.tab button.active {

background-color: #ccc;

}

 

.tabcontent {

display: none;

padding: 6px 12px;

border: 1px solid #ccc;

border-top: none;

}

</style>

</head>

<body>

 

<p>탭 메뉴를 선택해 보세요</p>

 

<div class="tab">

<button class="tablinks">런던</button>

<button class="tablinks">파리</button>

<button class="tablinks">앙카라</button>

</div>

 

<div id="London" class="tabcontent">

<h3>런던</h3>

<p>런던 (영어: London)은 잉글랜드와 영국의 수도이다.</p>

</div>

 

<div id="Paris" class="tabcontent">

<h3>파리</h3>

<p>파리(Paris)는 프랑스의 수도이다.</p>

</div>

 

<div id="ankara" class="tabcontent">

<h3>앙카라</h3>

<p>터키의 수도이다.</p>

</div>

</body>

<script>

$(".tablinks:eq(1)").addClass("active");

$("#London").css('display', 'none');

$(".tablinks").click(function(event) {

selectedIndex = $(this).index();

$(".tabcontent").each(function(index, item) {

if (index == selectedIndex) {

$(item).css('display', 'none');

} else {

$(item).css('display', 'block');

}

});

$(".tablinks").each(function(index, item) {

if (index != selectedIndex) {

$(item).addClass("active");

} else {

$(item).removeClass('active');

}

});

});

</script>

</html>

 

수정된 코드

<!DOCTYPE html>
<html>
<head>
<style>
body {
 font-family: Arial;
}

 

.tab {
 overflow: hidden;
 border: 1px solid #ccc;
 background-color: #f1f1f1;
}

 

.tab button {
 float: left;
 border: none;
 outline: none;
 cursor: pointer;
 padding: 14px 16px;
 font-size: 17px;
}

 

.tab button:hover {
 background-color: #ddd;
}

 

.tab button.active {
 background-color: #ccc;
}

 

.tabcontent {
 display: none;
 padding: 6px 12px;
 border: 1px solid #ccc;
 border-top: none;
}
</style>
</head>
<body>
 
 <p>탭 메뉴를 선택해 보세요</p>

 

 <div class="tab">
  <button class="tablinks">런던</button>
  <button class="tablinks">파리</button>
  <button class="tablinks">앙카라</button>
 </div>

 

 <div id="London" class="tabcontent">
  <h3>런던</h3>
  <p>런던 (영어: London)은 잉글랜드와 영국의 수도이다.</p>
 </div>

 

 <div id="Paris" class="tabcontent">
  <h3>파리</h3>
  <p>파리(Paris)는 프랑스의 수도이다.</p>
 </div>

 

 <div id="ankara" class="tabcontent">
  <h3>앙카라</h3>
  <p>터키의 수도이다.</p>
 </div>
</body>
<script>  
    $(".tablinks:eq(0)").addClass("active");   // 런던탭의 색상이 #ccc로
    $("#London").css('display', 'none');
    $(".tablinks").click(function(event) {
        selectedIndex = $(this).index();      
        $(".tabcontent").each(function(index, item) {
            if (index != selectedIndex) {  // 같지 않으면
                $(item).css('display', 'none');
            } else {
                $(item).css('display', 'block');
            }
        });
        $(".tablinks").each(function(index, item) {
            if (index != selectedIndex) {
                $(item).addClass("active");
            } else {
                $(item).removeClass('active');  
            }              
        });
    });
</script>
</html>

 

양이 많아 압박받아서 그렇치 고칠곳든 2곳이였음...

+ Recent posts