0

我需要将 asp.net 中的文本框值传递给 javascript 变量 videoID 并将其保存到数据库中。

这是我的代码

<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: 'ASO_zypdnsQ',
events: {
'onReady': onPlayerReady
}
});
}
</script>
4

2 回答 2

1

尝试这个

如果您使用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>
于 2013-05-01T06:13:36.880 回答
0

如果是你的aspx页面请按如下操作

<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: '<% AspCode.VideoId %>',
events: {
'onReady': onPlayerReady
}
});
}
</script>

如果不是 Aspx 页面,可以在 js 文件中定义 javascript 变量

var videoId = '<% AspCode.VideoId %>';

而不是从变量中获取视频ID。

于 2013-05-01T05:15:17.857 回答