gpt4 book ai didi

javascript - 在 Bootstrap 中向菜单添加操作

转载 作者:太空宇宙 更新时间:2023-11-04 15:00:52 27 4
gpt4 key购买 nike

我正在进行 Bootstrap 。

<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Case</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
</head>
<body>

<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">TEST</a>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav">
<li><a href="#">Performance</a></li>
<li><a href="#">Book Library</a></li>
</ul>
</div>
</div>
</nav>

<div class="container">
<h3>Collapsible Navbar</h3>
<p>In this example, the navigation bar is hidden on small screens and replaced by a button in the top right corner (try to re-size this window).
<p>Only when the button is clicked, the navigation bar will be displayed.</p>
</div>

</body>
</html>

但是在这里,

我希望内容在点击表演时填写“这是表演”,在点击图书馆时填写“这是图书图书馆”。

单击菜单时如何添加操作?

最佳答案

我已将 id 添加到性能和库按钮

<li><a href="#" id="Performance">Performance</a></li>
<li><a href="#" id="Library">Book Library</a></li>

这是一段 javascript 代码

function click(e){
if(e.target.id=="Performance"){
document.getElementsByClassName('container')[0].innerHTML="this is performance";
}
if(e.target.id=="Library"){
document.getElementsByClassName('container')[0].innerHTML="this is library";
}
}
document.getElementById("Performance").addEventListener("click",click,false)
document.getElementById("Library").addEventListener("click",click,false);
<body>

<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Saurabh Shelar</a>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav">
<li><a href="#" id="Performance">Performance</a></li>
<li><a href="#" id="Library">Book Library</a></li>
</ul>
</div>
</div>
</nav>

<div class="container">
<h3>Collapsible Navbar</h3>
<p>In this example, the navigation bar is hidden on small screens and replaced by a button in the top right corner (try to re-size this window).
<p>Only when the button is clicked, the navigation bar will be displayed.</p>
</div>

</body>
</html>

关于javascript - 在 Bootstrap 中向菜单添加操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34428347/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com