我想用按鈕click.When我點擊播放按鈕,需要改變autoplay=0 to autoplay=1
更換指定的URL的一部分的查詢字符串,當我點擊關閉按鈕後,有變更autoplay=1 to autoplay=0
更改使用正則表達式
jQuery(document).ready(function($) {
$('.playButton').click(function() {
alert('play');
$("iframe").src = src.replace(/\&autoplay\=\d/, "&autoplay=" + 1);
});
$(".close_icon").click(function() {
alert('close');
$("iframe").src = src.replace(/\&autoplay\=\d/, "&autoplay=" + 0);
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<iframe src="https://www.youtube.com/embed/C0DPdy98e4c?width=640&autoplay=1"></iframe>
<div class="playButton">Play</div>
<div class="close_icon">Close</div>
使用'ATTR()'改變iframe的'src'屬性。 '$('iframe')。attr('src',function(i,oldSrc){return oldSrc.replace('autoplay = 0','autoplay = 1');});' – Tushar
@tushar你的帖子正在工作fine.Please再次張貼 – user3386779
這是[完整代碼(https://jsfiddle.net/tusharj/vqzkn1gp/) – Tushar