Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用jquery通过引导按钮显示特定的div_Javascript_Jquery_Html - Fatal编程技术网

Javascript 如何使用jquery通过引导按钮显示特定的div

Javascript 如何使用jquery通过引导按钮显示特定的div,javascript,jquery,html,Javascript,Jquery,Html,我有三个按钮:添加、溢出和损坏 当我按下添加按钮时,如何仅显示添加容器,如果按下溢出按钮,如何隐藏添加容器 这是我的片段 添加 宠坏 溢出来 使用数据目标显示所需的div $('.collapse').hide(); $(“.btn”)。单击(函数(){ $('.collapse').hide(); var$thisdata=$(this.attr('data-target'); console.log($thisdata) $($thisdata).show() }) 添加 宠

我有三个按钮:添加、溢出和损坏

当我按下添加按钮时,如何仅显示添加容器,如果按下溢出按钮,如何隐藏添加容器

这是我的片段


添加
宠坏
溢出来



  • 使用数据目标显示所需的div
  • $('.collapse').hide();
    $(“.btn”)。单击(函数(){
    $('.collapse').hide();
    var$thisdata=$(this.attr('data-target');
    console.log($thisdata)
    $($thisdata).show()
    })
    
    添加
    宠坏
    溢出来
    
    添加
    坏了
    溢出
  • 使用数据目标显示所需的div
  • $('.collapse').hide();
    $(“.btn”)。单击(函数(){
    $('.collapse').hide();
    var$thisdata=$(this.attr('data-target');
    console.log($thisdata)
    $($thisdata).show()
    })
    
    添加
    宠坏
    溢出来
    
    添加
    坏了
    溢出
    使用以下代码:

    <!DOCTYPE html>
    <html>
    <head>
    <style>
    .main_div{text-align:center; background: #00C492; padding:20px; width: 400px;}
    .inner_div{background: #fff; margin-top:20px; height: 100px;}
    .buttons a{font-size: 16px;}
    .buttons a:hover{cursor:pointer; font-size: 16px;}
    </style>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    <script>
    $(function() {
        $('#showdiv1').click(function() {
            $('div[id^=div]').hide();
            $('#div1').show();
        });
        $('#showdiv2').click(function() {
            $('div[id^=div]').hide();
            $('#div2').show();
        });
        $('#showdiv3').click(function() {
            $('div[id^=div]').hide();
            $('#div3').show();
        });
        $('#showdiv4').click(function() {
            $('div[id^=div]').hide();
            $('#div4').show();
        });
    })
    </script>
    </head>
    <body>
    <div class="main_div">
    <div class="buttons">
    <a class="button" id="showdiv1">Menu 1</a> | <a class="button" id="showdiv2">Menu 2</a> | <a class="button" id="showdiv3">Menu 3</a> | <a class="button" id="showdiv4">Menu 4</a>
    </div>
    <div class="inner_div">
    <div id="div1" style="display:none;">Hello, I'm Container one</div>
    <div id="div2" style="display:none;">Hello, I'm Container two</div>
    <div id="div3" style="display:none;">Hello, I'm Container three</div>
    <div id="div4" style="display:none;">Hello, I'm Container four</div>
    </div>
    </div>
    
    </body>
    </html>
    
    
    .main_div{文本对齐:中心;背景:#00C492;填充:20px;宽度:400px;}
    .inner_div{背景:#fff;页边顶部:20px;高度:100px;}
    .按钮a{字体大小:16px;}
    .按钮a:悬停{光标:指针;字体大小:16px;}
    $(函数(){
    $('#showdiv1')。单击(函数(){
    $('div[id^=div]')。hide();
    $('#div1').show();
    });
    $('#showdiv2')。单击(函数(){
    $('div[id^=div]')。hide();
    $('#div2').show();
    });
    $('#showdiv3')。单击(函数(){
    $('div[id^=div]')。hide();
    $('#div3').show();
    });
    $('#showdiv4')。单击(函数(){
    $('div[id^=div]')。hide();
    $('#div4').show();
    });
    })
    菜单1 |菜单2 |菜单3 |菜单4
    你好,我是集装箱一号
    你好,我是集装箱二号
    你好,我是三号货柜
    你好,我是四号货柜
    
    删除联机jquery链接并添加本地文件路径。

    使用以下代码:

    <!DOCTYPE html>
    <html>
    <head>
    <style>
    .main_div{text-align:center; background: #00C492; padding:20px; width: 400px;}
    .inner_div{background: #fff; margin-top:20px; height: 100px;}
    .buttons a{font-size: 16px;}
    .buttons a:hover{cursor:pointer; font-size: 16px;}
    </style>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    <script>
    $(function() {
        $('#showdiv1').click(function() {
            $('div[id^=div]').hide();
            $('#div1').show();
        });
        $('#showdiv2').click(function() {
            $('div[id^=div]').hide();
            $('#div2').show();
        });
        $('#showdiv3').click(function() {
            $('div[id^=div]').hide();
            $('#div3').show();
        });
        $('#showdiv4').click(function() {
            $('div[id^=div]').hide();
            $('#div4').show();
        });
    })
    </script>
    </head>
    <body>
    <div class="main_div">
    <div class="buttons">
    <a class="button" id="showdiv1">Menu 1</a> | <a class="button" id="showdiv2">Menu 2</a> | <a class="button" id="showdiv3">Menu 3</a> | <a class="button" id="showdiv4">Menu 4</a>
    </div>
    <div class="inner_div">
    <div id="div1" style="display:none;">Hello, I'm Container one</div>
    <div id="div2" style="display:none;">Hello, I'm Container two</div>
    <div id="div3" style="display:none;">Hello, I'm Container three</div>
    <div id="div4" style="display:none;">Hello, I'm Container four</div>
    </div>
    </div>
    
    </body>
    </html>
    
    
    .main_div{文本对齐:中心;背景:#00C492;填充:20px;宽度:400px;}
    .inner_div{背景:#fff;页边顶部:20px;高度:100px;}
    .按钮a{字体大小:16px;}
    .按钮a:悬停{光标:指针;字体大小:16px;}
    $(函数(){
    $('#showdiv1')。单击(函数(){
    $('div[id^=div]')。hide();
    $('#div1').show();
    });
    $('#showdiv2')。单击(函数(){
    $('div[id^=div]')。hide();
    $('#div2').show();
    });
    $('#showdiv3')。单击(函数(){
    $('div[id^=div]')。hide();
    $('#div3').show();
    });
    $('#showdiv4')。单击(函数(){
    $('div[id^=div]')。hide();
    $('#div4').show();
    });
    })
    菜单1 |菜单2 |菜单3 |菜单4
    你好,我是集装箱一号
    你好,我是集装箱二号
    你好,我是三号货柜
    你好,我是四号货柜
    

    删除联机jquery链接并添加本地文件路径。

    Bootstrap有一个名为的组件-它可能会帮助您。我相信这是一个更好的答案。然而,我有一个问题与他的,因为它显示了在不同的位置分区。TOP、Middle和BottomBootstrap都有一个名为-的组件,它可能会对您有所帮助。我相信这是一个更好的答案。然而,我有一个问题与他的,因为它显示了在不同的位置分区。顶部、中间和底部