gpt4 book ai didi

html - Bootstrap 下拉列表已展开且不会关闭

转载 作者:行者123 更新时间:2023-11-28 07:06:56 24 4
gpt4 key购买 nike

我在这里看到了几个关于下拉菜单何时不打开或打开后不关闭的问题。我的问题是下拉菜单在页面加载时加载为打开状态。这是我偶然发现的代码 ( http://jsfiddle.net/mariusc23/hts7F/ ) 的工作副本。我无法让我的菜单默认关闭。我的相关代码:

<html>
<head>
<script src="js/jquery.min.js" type="text/javascript"></script>
<script src="js/bootstrap.min.js" type="text/javascript"></script>
<script src="includes/dropdownfix.js" type="text/javascript"></script>
<link href="css/bootstrap.css" rel="stylesheet">
</head>

<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">

<ul class="nav navbar-nav navbar-right">
<li><a href="index.php">Home</a></li>
<li><a href="aboutus.php">About</a></li>
<li><a href="contactus.php">Contact</a></li>
<?php
if($profile_pic){
echo"<img src=\"".$profile_pic."\" />";
}
?>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><?php echo"$name"; ?>
<span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li><a href="index.php">test</a></li>

</ul>
</li>
</ul>
</div><!-- /.navbar-collapse -->

求助!我相信我也在使用 bootstrap 3.3.5。谢谢

编辑:我的错,这里是 dropdownfix.js,复制自 http://jsfiddle.net/mariusc23/hts7F/ .

// On dropdown open
$(document).on('shown.bs.dropdown', function(event) {
var dropdown = $(event.target);

// Set aria-expanded to true
dropdown.find('.dropdown-menu').attr('aria-expanded', true);

// Set focus on the first link in the dropdown
setTimeout(function() {
dropdown.find('.dropdown-menu li:first-child a').focus();
}, 10);
});

// On dropdown close
$(document).on('hidden.bs.dropdown', function(event) {
var dropdown = $(event.target);

// Set aria-expanded to false
dropdown.find('.dropdown-menu').attr('aria-expanded', false);

// Set focus back to dropdown toggle
dropdown.find('.dropdown-toggle').focus();
});

最佳答案

你想让这样的东西工作吗?: JSFiddle

<nav class="navbar navbar-default">
<div class="container">
<div class="collapse navbar-collapse" id="colapsableDropdown">
<ul class="nav navbar-nav navbar-right">
<li><a href="index.php">Home</a></li>
<li><a href="aboutus.php">About</a></li>
<li><a href="contactus.php">Contact</a></li>

<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="index.php">test</a></li>
</ul>
</li>
</ul>
</div>
</div>

如果仍然不起作用,那么我建议您打开您的开发者控制台(您的浏览器检查元素选项)并检查它,因为您可能缺少文件。

关于html - Bootstrap 下拉列表已展开且不会关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32891690/

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