我在我的html页面中使用了这个代码。单击图像"photo_medias“时,图像消失,视频iframe显示。它工作得很好,但是我想用这段代码创建一个jQuery函数。我不想让JavaScript在我的HTML中。有人能帮我吗?
<li class="mix videos">
<div onclick="this.nextSibling.style.display='block'; this.style.display='none'">
<img src="http://img.youtube.com/vi/<?php the_sub_field('youtube'); ?>/0.jpg" class="photo_medias" style="cursor:pointer" />
</div>
<div style="display:none">
<iframe class="youtube" src="//www.youtube.com/embed/<?php the_sub_field('youtube'); ?>" frameborder="0" allowfullscreen></iframe>
</div>
</li>发布于 2014-03-04 17:11:37
你能做到的
Fiddle Demo
$('.mix.videos div').click(function () {
$(this).hide().siblings().show();
});
或
Fiddle Demo
$('.mix.videos div').click(function () {
$(this).hide();
next_el = $(this).next().length ? $(this).next() : $(this).closest('.mix.videos').children().first();
next_el.show();
});https://stackoverflow.com/questions/22178392
复制相似问题