当我通过ajax调用用html替换div时,Bootstrap下拉菜单不起作用

时间:2015-03-31 06:14:53

标签: jquery css twitter-bootstrap

这是我的代码

<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
    <div class="jumbotron" id="rkhs">
        <h2 align="right" id="welcome">Welcome to RKHS Page</h2>
    </div>
    <div class="container">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse"
                data-target="#bs-example-navbar-collapse-1">
                <span class="sr-only">Toggle navigation</span> <span
                    class="icon-bar"></span> <span class="icon-bar"></span> <span
                    class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="homePage.jsp">Home</a>
        </div>
        <!-- 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">
                <li><a href="#" id="about">About</a></li>
                <li class="dropdown"><a href="#" class=""
                    data-toggle="dropdown" id="adHeading"> Admissions <b
                        class="caret"></b>
                </a>
                    <ul class="dropdown-menu">
                        <li><a href="#" id="admissions">Admission Details</a></li>
                        <li><a href="#" id="admissionsForm">Admissions Form</a></li>
                    </ul></li>
                <li class="dropdown"><a href="#" class="dropdown-toggle"
                    data-toggle="dropdown" role="button" aria-expanded="false">Dropdown
                        <span class="caret"></span>
                </a>
                    <ul class="dropdown-menu" role="menu">
                        <li><a href="#">Action</a></li>
                        <li><a href="#" id="admissions">Admissions</a></li>
                        <li><a href="#">Another action</a></li>
                        <li><a href="#">Something else here</a></li>
                        <li class="divider"></li>
                        <li><a href="#">Separated link</a></li>
                        <li class="divider"></li>
                        <li><a href="#">One more separated link</a></li>
                    </ul></li>
                <li><a href="#">Contact</a></li>
                <li class="lialign"><a href="login.jsp">Login</a></li>
            </ul>
        </div>
        <!-- /.navbar-collapse -->
    </div>
    <!-- /.container -->
</nav>

当我点击招生链接时,它正在运作。但是当我用id htmlChange替换带有html通过ajax调用的div时,招生下拉列表不起作用。最初当页面加载导航栏中的下拉菜单工作正常但是如果你通过ajax调用点击招生链接带有htmlChange的div被替换为html.after,没有下拉列表正在工作

2 个答案:

答案 0 :(得分:0)

https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js

在头标记中添加带脚本标记的添加js链接。

答案 1 :(得分:0)

在此链接中,我已解决您的问题。

http://embed.plnkr.co/shakJU7v0eU5ZUipxpHV/preview

转到code和index.html