我有一个代码与Javascript播放Youtube视频,而不是iframe,但我不知道如何。我是从PHP变量还是像[youtube]videoid[/youtube]这样的bbcode传递视频id?我只需要把视频代码传递给这个功能。所以请帮助我,也许这里已经讨论过了,但我找不到它(也许我不知道我到底要搜索什么)。以下是代码:
<script>
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
height: '390',
width: '640',
videoId: 'M7lc1UVf-VE', // remove if assign in php
events: {
}
});
}
</script>或者指定videoId: in php。
发布于 2014-10-03 17:04:54
videoId: <?php echo json_encode($videoId); ?>,JSON编码与JavaScript兼容,并将处理任何转义和可能不需要执行的操作。
发布于 2014-10-03 17:04:54
直接输出变量怎么样?
videoId: <?php echo json_encode($vIdVariable); ?>,https://stackoverflow.com/questions/26183307
复制相似问题