Jquery - 单击该按钮会在一个div中加载html但使另一个div不可见

时间:2017-07-02 20:17:31

标签: jquery html css bootstrap-4

我是Jquery的新手。我有3个div,第一个div是标题,第二个div包含幻灯片放映图像以及按钮,单击按钮时显示第三个div。第三个div加载了外部HTML文件。单击按钮后加载第三个div时,第二个div不可见。拜托,帮帮我吧。问题如下图所示 screenshot of the output screenshot

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="MainScreen.css">
<script type="text/javascript"></script>
<script src="MainScreenJavaScript.js"></script>
<script 
   src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js">
</script>
<style>
     body{
        font-family: "Times New Roman", Georgia, Serif;
         }
</style>


</head>
<body>

<!-- Navbar top -->
<div class="topnav" id="myTopnav">
<a href="#home" class="colors" >HOME</a>
<a href="Resume.html"  class="colors" >ABOUT</a>
<a href="contact.html" class="colors" >CONTACT</a>
<a href="#icon" class="icon" onclick="myFunction()">&#9776;</a>
</div>

<!--Slide show -->
<div class="slideshow-container ">
   <div class="mySlides fade">
   <img src="laptop.jpg" class="image">
   <div class="text">Keen to learn many things</div>
 </div>

 <div class="mySlides fade">
  <img src="travel2.jpg" class="image">
   <div class="text">Like to travel</div>
 </div>

 <div class="mySlides fade">
  <img src="education.jpg" class="image">
  <div class="text">Education and Background</div>
 </div>

 <div class="mySlides fade">
  <img src="cook1.jpg" class="image">
  <div class="text" >
    <button id="cookButton" onclick="loadExternalHtml()">Love for 
        Cooking</button>
  </div>
  </div>

  <a class="prev" onclick="plusSlides(-1)">&#10094;</a>
  <a class="next" onclick="plusSlides(1)">&#10095;</a>
  </div>
  <!-- dots-->
  <div style="text-align:center">
      <span class="dot" onclick="currentSlide(1)"></span>
      <span class="dot" onclick="currentSlide(2)"></span>
      <span class="dot" onclick="currentSlide(3)"></span>
      <span class="dot" onclick="currentSlide(4)"></span>
   </div>

   <div id="content"></div>

   <script type="text/javascript">
     var slideIndex =1;
      showSlides(slideIndex);

      function loadExternalHtml(){
          $(document).ready(function(){
           $("#cookButton").click(function(){
             $("#content").load("foodBlog.html"); //load html page onclicking the button

      });

    });
   }


  </script>

   </body>
 </html>

这是我的foodBlog.html

<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
 <link rel="stylesheet" 
      href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/
    bootstrap.min.css">
<script 
  src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js">
 </script>
   </head>

   <body>

  <div class="container" >
       <div class="row">
     <div class="col-md-4">
    <div class="thumbnail">
    <img src="text.jpg" class="img-rounded"  alt="text" 
   style="width:100%;height:250px">
   <h3>text</h3>
   <p>It is a street food</p>
  </div>
 </div>
  <div class="col-md-4 ">
   <div class="thumbnail">
    <img src="text1.jpg" class="img-rounded"  alt="text1" 
    style="width:100%;height:250px;">
  <h3>text1</h3>
   <p>text1</p>
 </div>
 </div>

 <div class="col-md-4">
   <div class="thumbnail">
    <img src="text2.jpg" class="img-rounded"  alt="text1" 
     style="width:100%;height:250px;">
    <h3>text2</h3>
     <p>text2</p>
    </div>
   </div>

  </div>
  </div>

 </body>
</html>

1 个答案:

答案 0 :(得分:0)

<div id="content"></div>

slideshow-container的孩子,行为取决于contentslideshow-container的CSS。当您将content移到slideshow-container之外时,您会看到什么?

另请尝试:float:left;overflow:hidden; content

比HTML和jQuery脚本更重要的是您用于此ID和类的CSS。