2013-05-16 38 views
0

我試圖用JavaScript代替我網站上的iframe內容。除了自動播放功能在iOS中不起作用外,此功能一切正常。YouTube自動播放查詢參數在OS中不起作用

<iframe id="gallery-video" class="yt-player" type="text/html" width="940" height="530" src="http://www.youtube.com/embed/cKJ1s7l3GrI?theme=light&rel=0&autohide=1&wmode=transparent&enablejsapi=1" frameloadVideoById border="0" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe> 

$('#gallery-video').attr('src','https://www.youtube.com/embed/' + vidID + '?autoplay=1'); 
+0

它正在爲我工​​作。試試這個:'console.log('https://www.youtube.com/embed/'+ vidID +'?autoplay = 1')'。或者也許你在元素被加載之前調用了那段代碼? – Pacha

回答

0

因爲您沒有發佈完整的代碼,所以很難說出問題。一種可能的原因可能是vidID未在該範圍內定義,或者在文檔完全加載之前調用該代碼段。使用$(document).ready(function())並再試一次。

您可以隨時使用Javascript的控制檯並檢查錯誤。有一個有用的語言結構來存儲控制檯中的值,你可以像這樣使用它:console.log(variable)。將variable替換爲您要替換的東西:console.log('https://www.youtube.com/embed/' + vidID + '?autoplay=1')