【问题标题】:Data-toggle and data-target are not working数据切换和数据目标不起作用
【发布时间】:2015-08-09 01:04:39
【问题描述】:

我一直在四处寻找不同的解决方案,但到目前为止没有一个能帮助我。我的下拉菜单不起作用,因为 data-toggle 和 data-target 没有“被识别”(至少这就是我认为它不起作用的原因)。我似乎找不到解决方案,所以我希望这里有人可以帮助我。代码如下:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
    <title>Bootstrap 101 Template</title>

    <!-- Bootstrap -->
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">

<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">

<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->

    <style>
        .box{
            background-color: #d3d3d3;
            border: 1px solid gray;
        }
    </style>
</head>
<body>

    <div class="navbar navbar-inverse">
        <div class="container">
            <div class="navbar-header">
                <a href="" class="navbar-brand">My Website</a>

                <button type="button" class="navbar-toggle" datatoggle="collapse" data-target=".navbar-collapse">

                    <span class="sr-only">Toggle navigation</span>

                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>


                </button>
            </div>

            <div class="collapse navbar-collapse">
                <ul class="nav navbar-nav">
                    <li><a href="">Page 1</a></li>
                    <li><a href="">Page 1</a></li>
                    <li><a href="">Page 1</a></li>

                </ul>

            </div>
        </div>
    </div>

    <h1>Hello, world!</h1>

    <div class="container">
        <div class="row">
            <div class="col-md-6 box">Content</div>
            <div class="col-md-6 box">Content</div>
        </div>
    </div>

    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
</body>
</html>

https://jsbin.com/jumuka/edit?html,output

【问题讨论】:

  • 请在您的帖子中包含所有相关代码,并且不要仅包含指向代码托管站点的链接。您的帖子应该独立于任何其他资源;考虑一下如果该网站将来出现故障会发生什么!

标签: twitter-bootstrap


【解决方案1】:

你有datatoggle="collapse",你需要data-toggle="collapse"

【讨论】:

    猜你喜欢
    • 2019-10-06
    • 2018-05-16
    • 2023-04-08
    • 2017-03-19
    • 2020-01-02
    • 1970-01-01
    • 1970-01-01
    • 2020-03-22
    相关资源
    最近更新 更多