单击导航中的链接后,更改Bootstrap .collapsed以隐藏菜单

时间:2018-11-21 13:18:00

标签: javascript html css twitter-bootstrap

我有一个按钮:

#import <sys/utsname.h>

@interface UIDevice (InternalName)
- (NSString*) internalModelName;
@end

@implementation UIDevice (InternalName)
- (NSString*) internalModelName {
    struct utsname systemInfo;
    uname(&systemInfo);
    return [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
}
@end

在此按钮上单击它是SVG徽标,出现菜单:

<button class="logo-navbar-toggle collapsed" type="button" data-toggle="collapse" data-target="#navbar" aria-controls="bs4navbar" aria-expanded="false">

在导航中单击<nav id="navbar" class="collapse"> 之一时,我希望按钮和导航栏消失。

我尝试过:

anchor links

但是它什么也没做?我该怎么办?

2 个答案:

答案 0 :(得分:-1)

If you want to hide something, you should use jQuery's .hide() method. Also you are not getting anchor element right. Do this-

$('#navbar a').click(function (e) {
    $('.logo-navbar-toggle').hide(); //this hides button
    $('#navbar').hide(); //this hides navbar
});

答案 1 :(得分:-1)

尝试一下:

$('.navbar-collapse a').click(function (e) {
    $('.logo-navbar-toggle, .collapse').addClass('d-none');
  });