ExpressJS+Jade项目响应式导航栏折叠按钮点击无菜单显示求助
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 thedata-targetandaria-expandedattributes. 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-maincontainer 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') SOAConflicting 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.collapseclasses).
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

