javascript - 如何使用单个锚标记激活跳转链接并链接到 iframe?
问题描述
我想实现以下功能。当用户点击缩略图/链接时,该缩略图的图像将显示在 iframe 上,同时跳转到该缩略图的描述 - 谢谢
<style>
.flex-container{
display: flex;
}
.scrollBox{
overflow: auto;
width: 400px;
height: 530px;
}
</style>
<body>
<div class="flex-container">
<nav class="navigation">
<a href="../img/image1.png" target="full-size">
image1
</a>
<br>
<a href="../img/image2" target="full-size">
image2
</a>
</nav>
<iframe name="full-size" width="245" height="560"
src="../img/image1">
</iframe>
<div class="scrollBox">
<h1>Image1 Descriptions</h1[![enter image description here][1]][1]>
Lorem120
<hr>
<h2>Image2 Descriptions</h2>
Lorem200
</div>
</div>
</body>
我的尝试:当我点击缩略图时,它也会点击另一个跳转到描述的锚标签(我只是隐藏链接到描述的标签)。
<script>
function jumpToDescription(){
document.getElementsByTagName("a")[2].click();
}
</script>
<div class="flex-container">
<a href="../img/image1.png" target="full-size" onclick="jumpToDescription()">
image1
</a>
.
.
.
<a style="display: none" href="#image1Description">Image1</a>
</div>
我的问题是如何重写jumpToDescription()
以使函数可重用?而不是为具有唯一 .getElementsByTagName 索引号的每个缩略图创建一个唯一函数。另外,如果你们有比这更好的方法,我也愿意接受。- 谢谢你
解决方案
推荐阅读
- postgresql - 在 Postgresql 中创建和访问以数值开头的模式
- r - 将具有一个 id 和一个变量列的 data.table 转换为存在矩阵
- fortran - 尝试比较旧 fortran 中的不同类型
- python - 对 pandas DataFrame 中特定行的简单计算
- python - Django 属性错误 Str 对象主页
- c# - 使用 MVVM 模型将树视图和数据网格绑定到数据集
- azure-functions - 如何在 Azure Durable Functions 中保留变量
- python - 如何在正则表达式上匹配冒号后的字符串
- php - 如何在php中使用array_shift函数检查队列中的第一个人
- python - 在python中具有多个反斜杠匹配的正则表达式