0

我收到错误消息Uncaught TypeError: Property '$' of object [object Object] is not a function

调用后:

$('body').scrollspy({ target: '.nav.navbar-nav' })

以下是我构建代码的方式:

<body>
     <div class="outbox">         <nav class="navbar navbar-default navbar-fixed-top" role="navigation">   <div class="container-fluid">
     <!-- Brand and toggle get grouped for better mobile display -->
     <div class="navbar-header">
       <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
        <span class="sr-only">Toggle navigation</span>
         <span class="icon-bar"></span>
         <span class="icon-bar"></span>
         <span class="icon-bar"></span>
       </button>
      <a class="navbar-brand" href="http://www.google.de/"><strong>Google</strong></a>
     </div>

 <!-- Collect the nav links, forms, and other content for toggling -->
 <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
   <ul class="nav navbar-nav">      
     <li><a href="#link1">LINK 1</a></li>
     <li><a href="#link2">LINK2</a></li>
     <li><a href="#link3">LINK3</a></li>       
   </ul>    
</div><!-- /.navbar-collapse -->   </div><!-- /.container-fluid --> </nav>

[... CONTENT AREA ]

<div id="link1" class="container"></div> 
<div id="link2" class="container"></div> 
<div id="link3" class="container"></div> 


 <script src="js/jquery-1.10.2.min.js"></script>
 <script src="js/bootstrap.min.js"></script>      
 <script src="js/lib/bootstrap-scrollspy.js"></script>

有人知道这个问题的解决方案吗?

4

1 回答 1

2

在body中,需要data-target在js中初始化and。

$('body').scrollspy({ target: '.navbar-collapse' })

而不是直接定位,ul您需要定位div绑定 ul。

<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
   <ul class="nav navbar-nav">      
     <li><a href="#link1">LINK 1</a></li>
     <li><a href="#link2">LINK2</a></li>
     <li><a href="#link3">LINK3</a></li>       
   </ul>    
</div>

bootply 工作示例

于 2014-02-08T09:29:04.003 回答