我正在尝试使两件事淡入,一件事是在选择一个链接时淡入,另一件事是在选择另一个链接时淡入?
对,我有 4 个 div,我希望 1 和 3 在单击链接时淡入,2 和 4 在单击另一个按钮时淡入。我正在使用 JQuery。这是我到目前为止所得到的:
<div id="video selector" style="float: right; width: 250px; background-color:#f3f3f3; height: 210px; margin-bottom:13px;">
<a href="#">
<script>
$(document.body).click(function () {
$("#1").fadeIn("slow");
$("#3").fadeIn("slow");
$("#2").hide();
$("#4").hide();
});
</script>
<img src="img/electronic recycling play.png" style="width:220px; padding-left:15px; padding-top:12px; padding-bottom:9px; cursor:pointer;" />
</a>
<center>Electronic Recycling</font></center>
</div>
这个正在加载 div 1 和 3。
<div id="video selector2" style="float: right; width: 250px; background-color:#f3f3f3; height: 210px;">
<a href="#">
<script>
$(document.body).click(function () {
$("#2").fadeIn("slow");
$("#4").fadeIn("slow");
$("#1").hide();
$("#3").hide();
});
</script>
<img src="img/battery recycling play.png" style="width:220px; padding-left:15px; padding-top:12px; padding-bottom:9px; cursor:pointer;" />
</a><center>Battery Recycling</font></center>
</div>
这个正在加载 div 2 和 4。
问题是它们都加载相同的 div(2 和 4),并且视频不会切换,只需重新加载同一个,按下您的枯萎按钮...有什么想法吗?
Right, I have 4 divs, I want 1 and 3 to fade in when a link is clicked, and 2 and 4 to fade in when the other button is clicked. I'm using JQuery. Here's what I've got so far:
<div id="video selector" style="float: right; width: 250px; background-color:#f3f3f3; height: 210px; margin-bottom:13px;">
<a href="#">
<script>
$(document.body).click(function () {
$("#1").fadeIn("slow");
$("#3").fadeIn("slow");
$("#2").hide();
$("#4").hide();
});
</script>
<img src="img/electronic recycling play.png" style="width:220px; padding-left:15px; padding-top:12px; padding-bottom:9px; cursor:pointer;" />
</a>
<center>Electronic Recycling</font></center>
</div>
This one is loading divs 1 and 3.
<div id="video selector2" style="float: right; width: 250px; background-color:#f3f3f3; height: 210px;">
<a href="#">
<script>
$(document.body).click(function () {
$("#2").fadeIn("slow");
$("#4").fadeIn("slow");
$("#1").hide();
$("#3").hide();
});
</script>
<img src="img/battery recycling play.png" style="width:220px; padding-left:15px; padding-top:12px; padding-bottom:9px; cursor:pointer;" />
</a><center>Battery Recycling</font></center>
</div>
This one is loading divs 2 and 4.
The problem is they both load the same divs (2 and 4), and the video doesn't switch, just reloads the same one, wither button you press... any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将 id 添加到您的 a 标记,如下所示:
然后在文档就绪函数中添加单击事件处理程序,如下所示:
上面的代码可以放在页面的头部而不是 a 标记的内容中。它添加了事件处理程序,以便当单击 id 为firstlink 的标签时,它会执行该函数。可以为下一个链接完成类似的功能。
Add an id to your a tag like this:
Then in the document ready function add the click event handler like this:
The above code can go in the head of your page rather than in the content of the a tag. It adds the event handler such that when the a tag with id firstlink is clicked it executes the function. A similar function can be done for the next link.