2012-05-07 2 views
0

jQuery를 사용하여 페이지의 섹션을 표시하거나 숨 깁니다. 이 접근 방식은 Chrome, FF 및 Safari에서 작동하지만 IE8 및 7에서는 중단됩니다. 애니메이션, 페이드 및 불투명도를 사용하여 시도했습니다. IE에서 아무것도 작동하지 않는 것 같습니다. IE Developer Tools의 js 콘솔에 따르면 선택된 요소에 '활성'클래스가 있지만 Dev Tools HTML 창에서 dom 트리를 보면 활성 클래스가 DOM에 제거되거나 다시 작성되지 않았습니다. .IE8 이하에서 jQuery 클래스를 추가/제거 할 수 없습니다.

마크 업

<nav> 
<ul> 
<li id="foo">Show Section 1</li> 
<li id="bar">Show Section 2</li> 
</ul> 
</nav> 

<div id="items"> 
<section class="foo">Content Section 1</section> 
<section class="bar">Content Section 2</section> 
</div> 

CSS의

#items > section {display: none;} 
.active {display: block;} 

어떤 조언을 크게 평가되는 JS

$('nav li').click(function(){ 
    var $me = $(this); 
showSection($me.attr('id')); 
}); 

showSection function(whichSection){ 
    $('#items > section').removeClass('active');  
    $('#items > '+'.'+whichSection).addClass('active'); 
} 

. 나는 심한 기한을 넘기고있다. 건배.

+5

IE8에 HTML5 태그를 인식 시키려면 html5shiv (또는 Modernizr)를 포함해야 할 수도 있습니다. – Adam

+0

귀하의 HTML이 유효성을 검사합니까? 또한 아담의 의견을 참조하십시오. – Sparky

+0

예제가 어디에서 어떻게 작동하는지 알 수 없습니다. – j08691

답변

2

ID와 클래스가 섞여 있습니다. 당신이 태그를 알고 강제하지 않는 한 아래

$('nav li').click(function(){ 
    var $me = $(this); 
    showSection($me.attr('id')); 
}); 

showSection function(whichSection){ 
    $('#items > section').removeClass('active');  
    $('#items > #' + whichSection).addClass('active'); 
} 
+0

감사합니다. Nick 방금 들었습니다. 나는이 예제 코드를 위해 바이올린을 만들어야했다. 나는 약간의 피드백을 얻으려고 서두르고 있었다. 도와 주셔서 감사합니다. 원래의 질문은 그대로 남아 있기 때문에, 특히 IE에서 일어날 수있는 다른 일에 대한 아이디어가 있다면 알려 주시기 바랍니다. –

1

당신은 선언이 잘못 작동 :

function showSection (whichSection){ 
     $('#items > section').removeClass('active');  
     $('#items > #' + whichSection).addClass('active'); 
    } 

또는

var showSection = function(whichSection){ 
     $('#items > section').removeClass('active');  
     $('#items > #' + whichSection).addClass('active'); 
    } 

참고 : IE는section을 이해하지 않습니다. 사용할 수 있습니다html5shiv/Modernizr. HTML5 태그를 찾으십시오.

+0

감사합니다. 나는 예제 코드를 작성하는 데 정말로 열의가 없었다. 실제 버전에서는 함수가 객체 메소드입니다. –

관련 문제