간단하고 분명해야하지만, 내가 왜 여기 잘못 된거야. 간단한 자바 스크립트 표시/숨기기 콘텐츠. 표시 차단 - 없음과 표시 여부 - 표시/숨김을 모두 시도했습니다. 작동하지 않습니다. npctext_X라는 모든 div 표시가 visible로 설정된 경우 작동합니다. 하지만 난 당신이 CSS 클래스를 사용하여 추가하거나에서 해당 클래스를 제거해야 문제에 대한 모범 사례 및 잠재적 인 솔루션으로자바 스크립트 내용 숨기기 해제
<script type="text/javascript">
function npcfunkc(karodyt,senas){
var showit = 'npctext_'+karodyt;
var hideit = 'npctext_'+senas
//document.getElementById(showit).style.display='block';
//document.getElementById(hideit).style.display='none';
document.getElementById(showit).style.visibility = 'show';
document.getElementById(hideit).style.visibility = 'hidden';
}
</script>
<div class='npctalk'>
<div id='npctext_1' style='visibility:visible;'>text 1 text 1 text 1 <br /><br />
<button onclick='npcfunkc(2,1)'>show 2 [hide 1]
</button><br />
<button onclick='npcfunkc(3,1)'>show 3 [hide 1]
</button><br />
</div>
<div id='npctext_2' style='visibility:hidden;'>text 2 text 2 text 2 <br /><br />
<button onclick='npcfunkc(1,2)'>show 1, [hide 2]
</button><br />
<button onclick='npcfunkc(3,2)'>show 3, [hide 2]
</button><br />
</div>
<div id='npctext_3' style='visibility:hidden;'>text 3 text 3 text 3 <br /><br />
<button onclick='npcfunkc(2,3)'>show 2, [hide 3]
</button><br />
<button onclick='npcfunkc(1,3)'>show 1, [hide 3]
</button><br />
</div>
</div>
안녕하세요, stackoverflow! 마크 업과 관련된 도움이 필요하면 faq 섹션을 참조하십시오. 마크 업에 대한 코드 들여 쓰기를 편집했습니다. - http://stackoverflow.com/editing-help – Smamatti
YUI 또는 jQuery와 같은 JS 라이브러리를 사용하지 않는 특별한 이유가 있습니까? –
display : block/none을 사용해 보았으므로이 스크립트는 저에게 효과적입니다 – david