.NET MVC引导程序:shown.bs.dropdown不起作用 [英] .NET MVC Bootstrap: shown.bs.dropdown Not Working

查看:130
本文介绍了.NET MVC引导程序:shown.bs.dropdown不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用ID为'navul'的ul进入'shown.bs.dropdown'事件.似乎无法使其正常运行.这是我的脚本:

I'm trying to tap into the 'shown.bs.dropdown' event on the ul with the id of 'navul'. Can't seem to get it working. Here's my script:

<script>
    $('#navul').on('shown.bs.dropdown', function () {
        alert('hello');
    })
</script>

这是我的HTML:

<div class="navbar navbar-inverse">
    <div class="container">
        <ul id="navul" class="nav navbar-nav">
            <li role="presentation" class="dropdown">
                <a data-toggle="dropdown" href="#"><img src="/Content/images/IconsNav/nav_appts.png" style="padding: 0px 5px 3px 0px;">Appointments<span class="caret"></span></a>
                <ul class="dropdown-menu" role="menu">
                    <li>@Html.ActionLink("YourAppointments", "YourAppointments", "Appointments")</li>
                    <li>@Html.ActionLink("Schedule Appointment", "ScheduleAppointment", "Appointments")</li>
                </ul>
            </li>
        </ul>
    </div>
</div>

我从没有收到警报.我究竟做错了什么?我正在解决这个问题:

I never get the alert. What am I doing wrong? I'm working off this:

http://getbootstrap.com/javascript/#dropdowns

谢谢!

推荐答案

.on事件将仅在调用.on时已存在的元素中注册事件,如果脚本过早,则不会注册该事件.注册,请尝试在就绪的jquery文档中加载,即:

The .on event will only register the event if the element already exists when .on is called, if your script is too soon, it won't register, try loading in the jquery document ready, ie:

<script>
    $(function() {
        $('.navbar').on('shown.bs.dropdown', function () {
            alert('hello');
        })
    });
</script>

这篇关于.NET MVC引导程序:shown.bs.dropdown不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆