2016-12-28 33 views
-1

我想在iframe中找到src並在jquery中添加autoplay=1。我想要找到iframe中的src,並且必須添加autoplay=1,現在我沒有找到src和追加autoplay=1找到屬性'src'並在jquery中添加'autoplay = 1'

$('.flex-active-slide iframe').contents().find("iframe").contents().find("src").append($("&autoplay=1")); 

jQuery(document).ready(function($){ 
 
    $(".playButton").on('click',function(){ 
 
    $('.flex-active-slide iframe').contents().find("iframe").contents().find("src").append($("&autoplay=1")); 
 
    }); 
 
    });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<div class="playButton">Play</div> 
 
<div class="flex-active-slide"> 
 
<iframe src=""> <!--But refering this--> 
 
    #document 
 
    <html> 
 
     <body> 
 
     <iframe src=""><!--want to refer this iframe --> 
 
      #document 
 
      <html> 
 
       <body> 
 

 
       </body> 
 
      </html> 
 
     </iframe> 
 
     </body> 
 
    </html> 
 
<iframe> 
 
    </div>

+0

問題在哪裏? – Sojtin

回答

0

您需要找到iframe中的特定元素並在其中添加自動播放
例如,我用視頻標籤作爲樣本

jQuery(document).ready(function($){ 
    $(".playButton").on('click',function(){ 
     $('.flex-active-slide iframe').contents().find("iframe").contents().find("video").each(function(){ 
      var videosrc=$(this).attr("src")+"&autoplay=1"; 
      $(this).attr("src",videosrc); 
     }); 
    }); 
}); 
相關問題