带有启动选项卡的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")
)