我試圖從下拉菜單中選擇不同的選項時,要讓div內的內容發生更改。在工作之前,我在div內部有了選項卡,但他們看起來很醜,所以我放棄了他們的下拉菜單。我將在下拉菜單中引用地圖或網格,以供用戶在稍後執行時使用。下拉選擇無法更改div內容
工作代碼:http://codepen.io/MarkBond/pen/aOJLqm
HTML:
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<div class="row">
<div class="col-lg-12">
<div class="ibox float-e-margins">
<div class="ibox-title">
<h5>Elements Map </h5>
<div class="ibox-tools">
<button class="btn btn-default dropdown-toggle btn-xs btn-purple" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-expanded="true">
Views
<span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
<li class="active" role="presentation"><a role="menuitem" tabindex="-1" href="#1">Map</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#2">List</a></li>
</ul>
<button type="button" class="btn btn-green btn-xs" data-toggle="modal" data-target="#myModal">Reset All</button>
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">
<span class="glyphicon glyphicon-remove"></span>
</button>
<h4 class="modal-title">Element Map</h4>
</div>
<div class="modal-body">
<p>Are you sure?</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<button type="button" class="btn btn-default btn-xs" data-toggle="modal" data-target="#myModal">
<span class="glyphicon glyphicon-fullscreen"></span>
</button>
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">
<span class="glyphicon glyphicon-remove"></span>
</button>
<h4 class="modal-title">Element Map</h4>
</div>
<div class="modal-body">
<p>Some text in the modal.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<a class="collapse-link">
<i class="fa fa-chevron-up"></i>
</a>
</div>
</div>
<div class="ibox-content">
<div class="active" id="1">
Lorem ipsum dolor sit amet, charetra varius quam sit amet vulputate. Quisque mauris augue, molestie tincidunt condimentum vitae, gravida a libero. Lorem ipsum dolor sit amet, charetra varius quam sit amet vulputate. Quisque mauris augue, molestie tincidunt
condimentum vitae, gravida a libero. Lorem ipsum dolor sit amet, charetra varius quam sit amet vulputate. Quisque mauris augue, molestie tincidunt condimentum vitae, gravida a libero. Lorem ipsum dolor sit amet, charetra varius quam sit amet
vulputate. Quisque mauris augue, molestie tincidunt condimentum vitae, gravida a libero. Lorem ipsum dolor sit amet, charetra varius quam sit amet vulputate. Quisque mauris augue, molestie tincidunt condimentum vitae, gravida a libero. Lorem
ipsum dolor sit amet, charetra varius quam sit amet vulputate. Quisque mauris augue, molestie tincidunt condimentum vitae, gravida a libero.
</div>
<div id="2">
Secondo sed ac orci quis tortor imperdiet venenatis. Duis elementum auctor accumsan. Aliquam in felis sit amet augue. Secondo sed ac orci quis tortor imperdiet venenatis. Duis elementum auctor accumsan. Aliquam in felis sit amet augue. Secondo sed ac
orci quis tortor imperdiet venenatis. Duis elementum auctor accumsan. Aliquam in felis sit amet augue. Secondo sed ac orci quis tortor imperdiet venenatis. Duis elementum auctor accumsan. Aliquam in felis sit amet augue. Secondo sed ac orci
quis tortor imperdiet venenatis. Duis elementum auctor accumsan. Aliquam in felis sit amet augue.
</div>
</div>
</div>
</div>
</div>
CSS:
.btn-green {
background-color:#33CC33;
color: #FFFFFF;
}
.btn-blue {
background-color:#3333FF;
color: #FFFFFF;
}
.btn-purple {
background-color:#CC00FF;
color: #FFFFFF;
}
.nav-dropdown-style {
font-weight: 600;
padding: 4px 12px;
margin: 14px 5px 5px 20px;
font-size: 14px;
float: right;
background: #1ab394;
}
.nav-dropdown-style:hover {
background: #199d82;
}
你認爲寫js代碼來做到這一點嗎?這將是相對容易:)使用JavaScript的 – SzybkiSasza
將使這容易很多。您可以搜索更改功能的下拉菜單並相應地隱藏和顯示div –
我正在考慮使用js,但我並不真正熟悉它。 –