問題描述
使用 jQuery 按鈕單擊更改 iFrame 的 URL? (Change URL of iFrame with jQuery button click?)
我試圖弄清楚如何在單擊藍色按鈕後更改此 iframe 中的視頻。因此,換句話說,單擊藍色按鈕將更改 iframe 中正在播放的視頻。
如果有人知道如何做到這一點,請告訴我...
HTML
<div id="stage">
<iframe width="560" height="315" src="https://www.youtube.com/embed/e‑ORhEE9VVg" frameborder="0" allowfullscreen></iframe>
</div>
<br>
<div id="button">Click me</div>
CSS
#button{
background:blue;
cursor:pointer;
width:200px;
margin‑left:auto;
margin‑right:auto;
color:white;
}
jQuery
$(document).on('click', '#button', function(event) {
});
參考解法
方法 1:
Consider this:
$( "#button" ).click(function() {
$("#stage > iframe").attr("src", "http://www.wp.pl");
});
Where http://www.wp.pl
is just a link for you to replace. You can always try to do it with somekind of loop to get more songs.