引导菜单崩于阿贾克斯的网站。如何关闭菜单上的每一个点击?菜单、网站、阿贾克斯

2023-09-10 18:09:21 作者:小男人i

我的网站上使用Ajax,我想关闭引导的倒塌菜单每次用户点击点击每一个菜单项,类似这样的code。但是,这code不起作用!该死的!

  $('菜单项)。点击(函数(){
$('崩溃')塌(隐藏)。
});
 

我该如何解决这个问题?

(菜单的code是一个简单的引导3.0.0):

 <按钮式=按钮级=导航栏,切换数据切换=崩溃数据目标=&GT导航栏崩溃。
<跨度类=图标栏>< / SPAN>
<跨度类=图标栏>< / SPAN>
<跨度类=图标栏>< / SPAN>
< /按钮>
 

和菜单中的code:

 < D​​IV CLASS =COL-MD-6 downmy>
< D​​IV CLASS =导航栏崩溃中的风格=高度:汽车;>
< D​​IV CLASS =menuTop>< UL ID =菜单主级=净值资产净值 - 丸><李ID =菜单项-605类=菜单项菜单 - 项目型自定义菜单项对象定制当前菜单项current_page_item菜单项,主菜单项-605>< A HREF =1.htm>家< / A>< /李>
<李ID =菜单项-314类=菜单项菜单项型post_type菜单项对象页菜单项-314>< A HREF =2.htm >我的帖子< / A>< /李>
<李ID =菜单项-315类=菜单项菜单项型post_type菜单项对象页菜单项-315>< A HREF =3.htm >给我留言< / A>< /李>
< / UL>
< / DIV>
< / DIV>
< / DIV>
 
为什么打开一个网页后再打开第二网页的时候,第一个网页就关掉了

解决方案

在带班.collapse的倒闭或成为可见的元素的.collapse类将由更换。在类。所以,你将不得不申请你隐藏在。在类了。

  $('菜单项)。点击(函数(){
    $(在。)崩溃(隐藏)。
});
 

您的菜单项包含一个锚,当此单击一个新的页面打开...所以我不明白你的问题。为prevent此添加事件preventDefault(的http:// API。 jquery.com/event.$p$pventDefault/ )到code:

  $('菜单项)。点击(函数(事件){
    。事件preventDefault();

$(在。)崩溃(隐藏)。
});
 

my website uses Ajax and i want to close the Bootstrap's collapsed menu every time a user click click on every menu item, like this code. But this code doesn't work!! Damn!

$('.menu-item').click(function() {
$('.collapse').collapse('hide');
});

How can I fix it?

(The code of menu is a simply bootstrap 3.0.0):

<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>

And the code of menu:

<div class="col-md-6 downmy">
<div class="navbar-collapse in" style="height: auto;">
<div class="menuTop"><ul id="menu-primary" class="nav nav-pills"><li id="menu-item-605" class="menu-item menu-item-type-custom menu-item-object-custom current-menu-item current_page_item menu-item-home menu-item-605"><a href="1.htm">Home</a></li>
<li id="menu-item-314" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-314"><a href="2.htm">My Posts</a></li>
<li id="menu-item-315" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-315"><a href="3.htm">Guestbook</a></li>
</ul>
</div>
</div>
</div>

解决方案

When an element with class '.collapse' collapse or become visible the '.collapse' class will be replace by the .in class. So you will have to apply your hide on the .in class too.

$('.menu-item').click(function() {
    $('.in').collapse('hide');
});

Your menu items contain an anchor, when click this a new page will open... so i don't understand your question. To prevent this add an event.preventDefault (http://api.jquery.com/event.preventDefault/) to your code:

$('.menu-item').click(function(event) {
    event.preventDefault();

$('.in').collapse('hide');
});