在另一个 div 内切换 div

发布于 2024-08-30 10:32:10 字数 724 浏览 1 评论 0原文

我在同一页面上有多个切换 div,并且我要切换的 div 必须显示在同一个 div 中。

我在一个名为“box”的 div 中,有六个名为“1”、“2”、“3”、“4”等的 div,它们都是隐藏的。如果我单击名为“1”的 a 标记,它将在“box”div 中显示 div 1 的内容。如果我点击名为“2”的标签 a,div 2 的内容将显示在“box”中并隐藏 div 1,依此类推。

我的问题是,如果 div 2 显示,我无法隐藏 div 1

这是我的代码:

$(document).ready(function () {
    $('#content1').hide();
    $('#content').hide();
    var Prutswonder;
    $('a.aici').click(function () {
        $('#content1').toggle('slow');
    });

    $('a.acolo').click(function () {
        $('#content').toggle('slow');
    });

    $("#" + Prutswonder).show("slow");
    $(".toggle").not("#" + Prutswonder).hide("slow");
});

我需要一个 if 函数来隐藏除显示的 div 之外的所有内容。

I have multiple toggle divs on the same page, and the div I'm toggling must be displayed in the same div.

I have, in a div called 'box', six divs named '1', '2', '3', '4', etc., and they are all hidden. If I click on an a tag named '1' it will display the contents of div 1 in 'box', div. If I click tag a named '2', the contents of div 2 will display in 'box' and hide div 1, and so on.

My problem is that I haven`t been able to hide div 1 if div 2 is showing

This is my code:

$(document).ready(function () {
    $('#content1').hide();
    $('#content').hide();
    var Prutswonder;
    $('a.aici').click(function () {
        $('#content1').toggle('slow');
    });

    $('a.acolo').click(function () {
        $('#content').toggle('slow');
    });

    $("#" + Prutswonder).show("slow");
    $(".toggle").not("#" + Prutswonder).hide("slow");
});

I need an if function to hide all except the div that is showing.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

谢绝鈎搭 2024-09-06 10:32:10

您可以隐藏所有 div,然后显示您想要的......

<script>
    // i'm assuming all your divs' names begins with 'content'
     $(document).ready(function(){   
       $('#content1').hide();
       $('#content').hide();

       $('a.aici').click(function(){
         $("div[id^='content']").hide();
         $('#content1').toggle('slow');
       });

       $('a.acolo').click(function(){
         $("div[id^='content']").hide();
         $('#content').toggle('slow');
       });

     });
</script>

You can hide all divs and then show the one you want...

<script>
    // i'm assuming all your divs' names begins with 'content'
     $(document).ready(function(){   
       $('#content1').hide();
       $('#content').hide();

       $('a.aici').click(function(){
         $("div[id^='content']").hide();
         $('#content1').toggle('slow');
       });

       $('a.acolo').click(function(){
         $("div[id^='content']").hide();
         $('#content').toggle('slow');
       });

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