Javascript 取消隐藏内容
应该简单明了,但我不明白这里有什么问题。简单的 javascript 显示/隐藏内容。尝试了显示 - 阻止/无和可见性 - 显示/隐藏。不工作.. 如果所有名为 npctext_X 的 div 可见性都设置为可见,则该方法有效。但我需要隐藏它们,因为这将用于对话......
<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>
Should be simple and clear, but I dont get what is wrong here. Simple javascript show/hide content. Tryed both display - block/none and visibility - show/hidden. Not working..
It works if all divs visibility named npctext_X are set to visible. but i need them to be hidden, becouse this will be used in as dialogues...
<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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
作为问题的最佳实践和潜在解决方案,您应该使用 CSS 类并从对象中添加或删除这些类。
这个教程可能会对您有所帮助。
As a best-practice and potential solution to your problem, you should use CSS classes and add or remove those classes from your objects.
This Tutorial may help you.
m您正在向您的函数发送整数。尝试用这样的引号将它们包裹起来,将它们转换为字符串......
mYou are sending integers to your function. Try wrapping them with quotes like this to convert them to string....