You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ExpressJS+Jade项目响应式导航栏折叠按钮点击无菜单显示求助

Troubleshooting Your Bootstrap Collapse Menu in Jade Template

Hey there! Let's dig into why your responsive navbar collapse button isn't expanding the menu when clicked. I've gone through your code and here are the most likely issues and fixes to try:

  • Missing Bootstrap JavaScript Dependencies
    Bootstrap's collapse feature relies on two key files: jQuery and Bootstrap's own JavaScript. If these aren't included in your template, the button won't trigger any action. Add these scripts (preferably at the end of your <body> tag to avoid loading delays) in your Jade code like this:

    script(src='https://code.jquery.com/jquery-3.6.4.min.js')
    script(src='/path/to/bootstrap.min.js')
    

    Double-check the file path if you're using a local copy of Bootstrap JS—incorrect paths are a common gotcha.

  • Syntax Error in Button Attributes
    Looking at your button code, there's a missing comma between the data-target and aria-expanded attributes. Jade requires commas to separate attributes, and this small mistake can prevent Bootstrap from recognizing the button's purpose. Fix that line to:

    button.navbar-toggle(type='button', data-toggle='collapse', data-target='#navbar-main', aria-expanded='false', aria-controls='navbar-main')
    
  • Incorrect Jade Indentation
    Jade uses indentation to define DOM structure, and a misaligned element can break Bootstrap's expected navbar hierarchy. Make sure your #navbar-main container is a direct sibling of .navbar-header (both should be indented under .container). Here's the corrected indentation for your full navbar code:

    body
      .navbar.navbar-default.navbar-fixed-top
        .container
          .navbar-header
            a.navbar-brand(href='/') MyBlogs
            button.navbar-toggle(type='button', data-toggle='collapse', data-target='#navbar-main', aria-expanded='false', aria-controls='navbar-main')
              span.sr-only Toggle navigation
              span.icon-bar
              span.icon-bar
              span.icon-bar
          #navbar-main.navbar-collapse.collapse
            ul.nav.navbar-nav
              li
                a(href='#about') About
              li
                a(href='#ADF') ADF
              li
                a(href='#SOA') SOA
    
  • Conflicting CSS/JavaScript
    Sometimes custom styles or third-party scripts can interfere with Bootstrap's collapse functionality. Try temporarily removing any non-Bootstrap CSS/JS files to see if the menu starts working. If it does, you'll need to isolate the conflicting code and adjust it (for example, checking for CSS that overrides Bootstrap's .collapse classes).

Start with fixing the attribute comma and verifying your JS includes—those are the most common causes for this issue. Let me know if any of these get your menu working!

内容的提问来源于stack exchange,提问作者Rupak kumar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 04:12:01