尝试这个
如果您使用asp:TextBox作为视频 id 比试试这个
<script>
var tag = document.createElement('script');
tag.src = "http://www.youtube.com/player_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var player;
function onYouTubePlayerAPI() {
player = new YT.Player('player', {
height: '350',
width: '600',
videoId: document.getElementsById('<% ClientID.VideoId %>').value,
events: {
'onReady': onPlayerReady
}
});
}
</script>
或者
如果你使用简单的html 文本框而不是试试这个
<script>
var tag = document.createElement('script');
tag.src = "http://www.youtube.com/player_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var player;
function onYouTubePlayerAPI() {
player = new YT.Player('player', {
height: '350',
width: '600',
videoId: document.getElementsByid("your textbox's ID").value,
events: {
'onReady': onPlayerReady
}
});
}
</script>