应该是简单明了的,但我没有得到这里的错误。简单的JavaScript显示/隐藏内容。尝试显示 - 块/无和可见性 - 显示/隐藏。不工作.. 如果所有名为npctext_X的div可见性都设置为可见,它将起作用。但我需要他们被隐藏,becouse这将是作为对话...Javascript取消隐藏内容
<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!请参阅常见问题解答部分,了解有关标记的任何帮助。我编辑了代码缩进标记。 - http://stackoverflow.com/editing-help – Smamatti
是否有一个特别的原因,为什么你不使用像YUI或jQuery的JS库? –
该脚本适用于我,因为我尝试过使用display:block/none – david