简体   繁体   中英

HTML, Javascript: How to share a container under specified bootstrap panels

<!DOCTYPE html>
<meta charset="utf-8">
<body>
    <div class="container-fluid">
        <div id="header">
            <div><a href="#" class="navbar-left"></a>
        </div>   
        <div id="content">
             <ul id="tabs" class="nav nav-tabs" data-tabs="tabs">
                 <li class = "nav-tabs"><a href="#a" data-toggle="tab">A</a></li>
                 <li class = "nav-tabs"><a href="#b" data-toggle="tab">B</a></li>
                 <li class = "nav-tabs"><a href="#c" data-toggle="tab">C</a></li>
             </ul>
             <div id="my-tab-content" class="tab-content">
                  <div class="tab-pane" id="a">
                       <div class="panel-body">A content</div>
                  </div>
                  <div class="tab-pane" id="b">
                       <div class="panel-body">B content</div>
                  </div>
                  <div class="tab-pane" id="c">
                       <div class="panel-body">C content</div>
                  </div>  
              </div>  
        </div>
    <br>
    <div class="row" id="container"> image </div>
</body>

This is the HTML code, I have a three column panel showing A, B and C using bootstrap.

Underneath the content, there is a container with id = "container" at the bottom of all panels.

Here is my question: I want to only have id = "container" shown under panel A, B. However, I don't want the panel C showing id = "container" . Is there any way to realize this?

You can use Hide()

 <script src="scripts/jquery-1.10.2.js"></script>
    <script>
        $(document).ready(function () {
            $("#c").hide();
        })
    </script>

Try this using jQuery:

$("#c").hasClass("active") {
    $("#container").hide()
} else {
    $("#container").show()
}

Or if you prefer a more CSS method:

$("#c").hasClass("active") {
    $("#container").css("visibility", "hidden")
} else {
    $("#container").css("visibility", "visible")
}

First add the class for the all '''li''' items

class = "nav-tabs"

Second, we need to add '''$(document).ready(function()''' to refresh the page, thus the "class" will be updated

$(".nav-tabs").on( "click", function() {
    $(document).ready(function() {
    bindClick();
    })
});

function bindClick(){
    if ( $("#c").hasClass("active")){
        $("#container").hide()
    } else {    
        $("#container").show();
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM