带有启动选项卡的jQuery事件触发 [英] Jquery event fire with bootstrap tab

查看:79
本文介绍了带有启动选项卡的jQuery事件触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在视图中使用引导程序选项卡

I am using bootstrap tab in my view

    @Html.ValidationSummary(true)
        <ul id="MyTabs" class="nav nav-tabs nav-justified">
            <li class="active"><a data-toggle="tab" href="#details" id="TabDetailsLink">Personal
                Details</a></li>
            <li><a data-toggle="tab" href="#tab1" id="Tab1">T1</a></li>
            <li><a data-toggle="tab" href="#tab2" id="Tab2">T2</a></li>

        </ul>

and i use jquery for catch the event
$(".MyTabs li").click(function (e) {
    alert(2);
});  

我希望每当我更改标签时都会收到警报.但是事件并没有被解雇.我的是一个ASP.NET MVC 4 Web API应用程序.

My expectation is to get the alert whenever I change the tabs. But the event is not getting fired. Mine is an ASP.NET MVC 4 web api application.

推荐答案

您的jQuery选择器错误! MyTabs是ID.因此,请使用#前缀

Your jQuery selector is wrong ! MyTabs is the Id. So use it with # prefix

这应该有效.

$("#MyTabs li").click(function (e) {
    e.prevelitDefault(); 
    alert(2);
});

或者,如果您将此类添加到yuur ul元素中,则可以使用现有的jQuery选择器.

Or you can use your existing jQuery selector if you add this class to yuur ul element.

<ul id="MyTabs" class="MyTabs nav nav-tabs nav-justified">

在将Id用作jQuery选择器时,请使用#前缀(例如:$("#myElementUniqueID"))

When using Id as your jQuery selector, use # prefix ( Ex : $("#myElementUniqueID"))

使用css类作为jQuery选择器时,请使用.前缀(例如:$(".myCssClss"))

When using css class as your jQuery selector, use . prefix ( Ex : $(".myCssClss") )

这篇关于带有启动选项卡的jQuery事件触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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