Bootstrap 4防止在单击内部时关闭下拉列表

时间:2016-11-05 11:46:02

标签: javascript html twitter-bootstrap

我在下拉列表中有一个表单。当我单击表单中的输入时,下拉菜单关闭。有没有办法阻止这个?

代码如下所示:

    <li class="nav-item dropdown">
        <a id="loginLink" class="nav-link dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Log in</a>
        <div id="loginModal" class="dropdown-menu dropdown-menu-right" role="dialog">
            <form class="dropdown-item" novalidate name="f1" ng-submit="login()">
                <div class="modal-body">
                    <div class="alert alert-danger" role="alert" ng-show="(error.length > 1)">
                        {{error}}
                    </div>
                    <div class="input-group">
                        <span class="input-group-addon" id="login-email-addon">Username:</span>
                        <input type="text" ng-model="userLoginEmail" class="form-control" placeholder="username" aria-describedby="login-email-addon" required>
                    </div>
                    <div class="input-group">
                        <span class="input-group-addon" id="login-pass-addon">Password:</span>
                        <input type="password" class="form-control" ng-model="userLoginPassword" placeholder="password" aria-describedby="login-pass-addon" required>
                    </div>
                </div>
                <div class="modal-footer">
                    <input type="submit" class="btn btn-primary" value="Log in" required />
                </div>
            </form>
        </div>
    </li>

我试着用它停止它:

$(document).ready(function () {
    $(document).on('click', '.dropdown-item', function (e) {
        e.stopPropagation();
    });
});

但这似乎并没有阻止它。实际上,当该方法运行时,菜单已经关闭

0 个答案:

没有答案