【发布时间】:2014-08-13 01:15:18
【问题描述】:
我有三个按钮,当你悬停(精灵)时会改变颜色,我想使用这些按钮,以便在单击它们时显示不同的内容。
我浏览了多个教程/板,但似乎没有任何效果。
按钮显示如下:
<div id="buttons">
<a href="#" id="1"class="des"></a>
<a href="#" id="2"class="brnd"></a>
<a href="#" id="3"class="strt"></a>
</div>
放置内容的div(我最后一次尝试)如下:
<div id="pages">
<div id="div1"><img src="..."></></div>
<div id="div2"><img src="..."></></div>
<div id="div3"><img src="..."></></div>
jQuery----
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
</head>
<script type="text/javascript">
$(document).ready(function() {
$("a").click(function() {
var id = $(this).attribute("data-id"); // Using a custom attribute.
$("#pages div").hide(); // gather all the div tags under the element with the id pages and hide them.
$(".div" + id).show(); // Show the div with the class of .divX where X is the number stored in the data-id of the object that was clicked.
});
});
</script>
我的锚似乎是错误的。有了这个设置,它就到了页面的顶部。使用锚#1、#2 或#3 时,它会转到 div 位置,但不会隐藏或显示内容。令人沮丧。
精灵工作正常。现在我正在尝试弄清楚如何使它们可点击,以便在单击每个按钮时显示不同的内容(3 个 div - 在父 div 下?)。如果有人确切地知道如何做到这一点,我将非常感激。
内容主要是图像,我正在使用带有前端编辑器的 Jupiter 主题,所以我不知道它是否可以。但是后端似乎没有任何问题。
另外,如果您可以向我指出一个教程,该教程将教我如何制作它,以便它们在单击时动画进出,那将是合法的。再次感谢。
【问题讨论】:
-
先发布你最近的尝试怎么样?此外,您可以通过删除前 3 个句子来大大提高这个问题的质量。
标签: javascript jquery css html wordpress