外部Jquery文件正在运行,但Jquery函数不起作用

时间:2017-10-06 10:03:31

标签: jquery html css angularjs twitter-bootstrap

我有HTML部分,主要的index.html和外部JQuery文件。我使用alert函数检查时正在加载文件,但JQuery函数没有被执行。

我检查了文件在网站上成功加载的资源。这可能有什么问题?

的index.html

<!DOCTYPE html>
<html lang="en">
<head> 
<!-- Required meta tags -->
<meta charset="UTF-8">
<base href="/" />
<!-- Optional JavaScript -->
    <!-- jQuery first, then Popper.js, then Bootstrap JS -->
    <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js"></script>

<!--Angular Library -->
<script src="library/angular.min.js"></script>
<script src="library/angular-route.min.js"></script>

<!--CSS -->
<link rel="stylesheet" href="css/style.css">

<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M" crossorigin="anonymous">

<!--Custom -->
<script type="text/javascript" src="js/route.js"></script>
<script type="text/javascript" src="js/animate.js"></script>
</head>
<body ng-app="myApp">
<div class="pos-f-t">
  <div class="collapse" id="navbarToggleExternalContent">
    <div class="bg-dark p-4">
    <div>
    <div id="logo">
    <img src="images/logo.jpg">
    </div>
    <div class="main_header">
      <ul class="nav nav-tabs">
  <li class="nav-item">
    <a class="nav-link text-white" href="/home">Home</a>
  </li>
  <li class="nav-item">
    <a class="nav-link text-white" href="/our_classes">Our Classes</a>
  </li>
  <li class="nav-item">
    <a class="nav-link text-white" href="/our_coaches">Our Coaches</a>
  </li>

   <li class="nav-item">
    <a class="nav-link text-white" href="/most_recent">Most Recent</a>
  </li>
   <li class="nav-item">
    <a class="nav-link text-white" href="/gallery">Gallery</a>
  </li>
   <li class="nav-item">
    <a class="nav-link text-white" href="/contact_us">Contact Us</a>
  </li>
  <li class="nav-item">
    <button type="button" class="btn btn-outline-primary" id="login_button">Log In</button>
  </li>
</ul>
</div>
    </div>
  </div>
  </div>
  <nav class="navbar navbar-dark bg-dark">
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarToggleExternalContent" aria-controls="navbarToggleExternalContent" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
  </nav>
</div>
<div ng-view></div>
<div class="main_footer">
<div id="social">
<div id="footer">
<img class="image" src="images/fb.png">
<img class="image" src="images/insta.png">
<img class="image" src="images/google.png">
</div>
</div>
</div>
</body>
</html>

home.html的

<div id="animate"><h1>This is animation.</h1></div>
<div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel">
  <ol class="carousel-indicators">
    <li data-target="#carouselExampleIndicators" data-slide-to="0" class="active"></li>
    <li data-target="#carouselExampleIndicators" data-slide-to="1"></li>
    <li data-target="#carouselExampleIndicators" data-slide-to="2"></li>
  </ol>
  <div class="carousel-inner">
    <div class="carousel-item active">
      <img class="d-block w-100" src="../images/carousel_1.jpg" alt="First slide">
    <div class="carousel-caption d-none d-md-block">
        <h1>BECOME A PRO DANCER</h1><br/>
        <h3> With our professional coaches,instructors, and choreographers you will master the professional dance techniques.</h3><br/>
        <button type="button" class="btn btn-primary btn-lg">Learn More</button>
     </div>
    </div>
    <div class="carousel-item">
      <img class="d-block w-100" src="../images/carousel_4.jpg" alt="Second slide">
    <div class="carousel-caption d-none d-md-block">
        <h1>EXPRESS YOURSELF IN DANCE</h1><br/>
        <h3> Since its opening,Dance Studio has become a unique place where teenagers,children, and adults can enjoy the art of dancing.</h3><br/>
        <button type="button" class="btn btn-primary btn-lg">Learn More</button>
    </div>
    </div>
    <div class="carousel-item">
      <img class="d-block w-100" src="../images/carousel_3.jpg" alt="Third slide">
      <div class="carousel-caption d-none d-md-block">
        <h1>THE ART OF MOVEMENT</h1><br/>
        <h3>Becoming a part of Dance Studio and learning your favourite style of dancing means enjoying means enjoying the essence of dance as kind of art. </h3><br/>
        <button type="button" class="btn btn-primary btn-lg">Learn More</button>
    </div>
    </div>
  </div>
  <a class="carousel-control-prev" href="#carouselExampleIndicators" role="button" data-slide="prev">
    <span class="carousel-control-prev-icon" aria-hidden="true"></span>
    <span class="sr-only">Previous</span>
  </a>
  <a class="carousel-control-next" href="#carouselExampleIndicators" role="button" data-slide="next">
    <span class="carousel-control-next-icon" aria-hidden="true"></span>
    <span class="sr-only">Next</span>
  </a>

</div>

animate.js

$(document).ready(function()
{
$("#animate").hide();
setInterval(function(){
$("#animate").fadeIn(1000);
},1000);
});

2 个答案:

答案 0 :(得分:0)

$(document).ready(function()
{
$("#animate").hide();
     setInterval(function(){
          $("#animate").fadeIn(2000);
        },1000);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="animate"><h1>This is animation.</h1></div>

答案 1 :(得分:0)

首先,在</body>之前移动所有js文件,但保存jquery和jquery依赖文件的顺序。您还可以为这些文件设置defer属性。此属性使文件逐步执行以便您设置