jQuery的:如何在更換視頻時停止視頻(Jquery)?
$(function() {
$('.videos').hide();
$(".bat").click(function() {
$('.videos').hide();
$('.morcego').slideDown();
$('.default').replaceWith(".morcego");
});
$('.hit').click(function() {
$('.videos').hide();
$('.careca').slideDown();
$('.default').replaceWith(".careca");
});
$('.metro').click(function() {
$('.videos').hide();
$('.metro-last').slideDown();
$('.default').replaceWith(".metro-last");
});
});
HTML:` 觀看和收聽我們的評論
<iframe width="900" height="400" src="https://www.youtube.com/embed/tl39XPeb7UE?rel=0&showinfo=0" frameborder="0" allowfullscreen class="videos morcego img-responsive"></iframe>
<iframe width="900" height="400" src="https://www.youtube.com/embed/g7uYfhWNvrA?rel=0&showinfo=0" frameborder="0" allowfullscreen class="videos careca img-responsive"></iframe>
<iframe width="900" height="400" src="https://www.youtube.com/embed/FDIjP6X9f98?rel=0&showinfo=0" frameborder="0" allowfullscreen class="videos metro-last img-responsive">></iframe>
</div>
<div class="videos-list-video">
<h3 class="align-center">Popular Videos</h3>
<div class=img-list>
<img src="img/batman_videos.jpg" class="img-responsive bat">
</div>
<div class=img-list>
<img src="img/hitman_videos.jpg" class="img-responsive hit">
</div>
<div class=img-list>
<img src="img/metro_videos.png" class="img-responsive metro">
</div>
</div>
</div>
程序工作正常,但視頻被更換時,另外一個也不會停止播放和你聽到了。我想我不能使用replaceWith()方法...任何建議?由於
它的作品,但只適用於蝙蝠俠視頻。如果蝙蝠正在玩並且你打電話給其他人,蝙蝠會停止,但是如果殺手正在玩並且你打電話給其他人,它不會停止。同樣是地鐵...我不明白... – icenine
檢查更新jsfiddle [鏈接](https://jsfiddle.net/h2a8qfh4/1/) – zakhefron
完美!謝謝! – icenine