Javascript 取消隐藏内容

发布于 2024-12-16 12:54:42 字数 1488 浏览 0 评论 0原文

应该简单明了,但我不明白这里有什么问题。简单的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

缘字诀 2024-12-23 12:54:42

作为问题的最佳实践和潜在解决方案,您应该使用 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.

虫児飞 2024-12-23 12:54:42

m您正在向您的函数发送整数。尝试用这样的引号将它们包裹起来,将它们转换为字符串......

npcfunkc("2", "1")

mYou are sending integers to your function. Try wrapping them with quotes like this to convert them to string....

npcfunkc("2", "1")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文