我在我的 html 页面中使用此代码。 单击图像“photo_medias”时,图像消失,视频 iframe 显示。它工作正常,但我想用这段代码创建一个 jQuery 函数。我不想在我的 HTML 中包含 JavaScript。有人可以帮我解决这个问题吗?
<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>
最佳答案
你可以做到
$('.mix.videos div').click(function () {
$(this).hide().siblings().show();
});
或者
$('.mix.videos div').click(function () {
$(this).hide();
next_el = $(this).next().length ? $(this).next() : $(this).closest('.mix.videos').children().first();
next_el.show();
});
关于javascript - function.js 中的 this.nextSibling,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22178392/