html - Fig caption doesn't change when i click on other images
问题描述
When i click on different images the fig caption says the same thing, i am trying to change it so when i click on different images, the fig caption changes.
I have attempted to change it and have only been able to put separate fig captions under each image. Not make the fig caption change depending on what image has been clicked.
<main id="gallery">
<h1> Get fit and stay fit with Betty Swannocks Fitness Center </h1>
<figure>
<img src="images/gym4.jpg" alt="gym photos">
<figcaption> Gym4 </figcaption>
</figure>
<ul>
<li><a href="images/gym1.jpg" title="gym1"><img src="images/gym1-150.jpg" width="150" height="100" alt="Fitness1"> </a> </li>
<li><a href="images/gym2.jpg" title="gym2"><img src="images/gym2-150.jpg" width="150" height="100" alt="Fitness2"> </a></li>
<li><a href="images/gym3.jpg" title="gym3"><img src="images/gym3-150.jpg" width="150" height="100" alt="Fitness3"> </a></li>
<li><a href="images/gym4.jpg" title="gym4"><img src="images/gym4-150.jpg" width="150" height="100" alt="Fitness4"> </a> </li>
<li><a href="images/gym5.jpg" title="gym5"><img src="images/gym5-150.jpg" width="150" height="100" alt="Fitness5"> </a> </li>
<li><a href="images/gym6.jpg" title="gym6"><img src="images/gym6-150.jpg" width="150" height="100" alt="Fitness6"> </a> </li>
</ul>
</main>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$('#gallery a').click(function(){
var galleryHref = $(this).attr('href');
var galleryAlt = $(this).attr('title');
$('figure img').attr({src:galleryHref, alt:galleryAlt});
return false;
});
})
</script>
</body>
</html>
I expected the fig caption to change based on the image that was clicked, it stays the same fig caption despite other images being clicked.
解决方案
推荐阅读
- c# - 为什么我没有从我的网络请求中得到任何东西?我应该寻找什么?
- c++ - 如何在 Gtkmm4 中获取 Gtk::Window 的 XId
- sql - 如何使用 oracle 查询找出以下输出
- javascript - 如何在 Map 中找到键,其中键包含某个值?
- java - 使用 Comsol API 在 Java 中出现 FlException:无法获取用户名和密码
- r - 是否可以使用 spData/tmap 包创建英国县的地图
- node.js - Google Translate API:音译输入
- mysql - 如何通过将一个表中的日期与另一个表中最接近和之前的日期匹配来连接两个表
- python - PyOpenCl 简单矩阵乘法
- authentication - JSF 2.3 基于表单的登录和 ViewExpiredException