gpt4 book ai didi

jquery - 如何让我的 div 显示选定的 youtube api 内容?

转载 作者:行者123 更新时间:2023-11-28 05:08:52 25 4
gpt4 key购买 nike

我不得不重新发布,因为没有人给我我想要的答案。

我试图在用户点击该视频下方的按钮时,它会在弹出窗口中显示该视频。但是,它只会在每次单击按钮时显示相同的视频。

<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>

<title>slider demo</title>
<link rel="stylesheet" type="text/css" href="style.css">
<link rel="stylesheet" type="text/css" href="js-image-slider.css">

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>


</head>
<body >
<style>
#myDIV {
display: none;
}
.display {
display: block;
}
.span2:focus ~ .alert {
display: none;
}
.span3:focus ~ .myDIV {
display: block;
padding: 20px;
background-color: #f44336;
color: white;
}/*
.alert{display:none;}
*/
.alert {
display:none;
}
.showdiv{

display: block;
padding: 20px;
background-color: #f44336;
color: white;
}
#video ~ #myDIV{
z-index: 1;
}
</style>
</head>
<body>
<div class="col-md-12 display"></div>
<p>Click the "Try it" button to toggle between hiding and showing the DIV element:</p>

<p id ="mydiv"onclick="myFunction()">Try it</p>

<div id="myDIV "><div class="display">
This is my DIV element.
</div>
</div>


<p><b>Note:</b> The element will not take up any space when the display property set to "none".</p>
<div id = "results"></div>
<script>
function myFunction() {
var x = document.getElementById('myDIV');
if (x.style.display === 'none') {
x.style.display = 'block';
x.style.color = 'blue';
x.style.position = 'absolute';
x.style.top = '20px';
x.style.left = '100px';
x.style.background = 'red';


} else {
x.style.display = 'none';
}
}
</script>
<script type="text/javascript">
$(document.ready(function(){
$('#select').click(function(){

$('#myDIV').append('<p>Hello world</p>');
});


});)
</script>
<script>
var channelName='ajaxkm';

$(document).ready(function()
{
$.get("https://www.googleapis.com/youtube/v3/channels",
{
part: 'contentDetails',
forUsername: channelName,
key: ''},
function(data)
{
$.each(data.items,function(i,item)
{
console.log(item);
pid=item.contentDetails.relatedPlaylists.uploads;
getVids(pid);
})


}
);
function getVids(pid){
$.get("https://www.googleapis.com/youtube/v3/playlistItems",
{
part: 'snippet',
maxResults: 10,
playlistId: pid,

key: ''},
function(data)
{
var output;
$.each(data.items,function(i,item)
{
console.log(item);
videTitle=item.snippet.title;
videoId = item.snippet.resourceId.videoId;
videoDescription = item.snippet.description;
output2='<div class="col-md-4 display"><iframe src=\"//www.youtube.com/embed/'+videoId+'\"></iframe><br><p id="show">'+videoDescription+'</p><span id ="span3" tabindex ="0"><p id ="select" onclick="myFunction()" > Discription of Video</p></span><p id="myDIV"><iframe id ="video" src =\"//www.youtube.com/embed/'+videoId+'\" ></iframe>'+videoDescription+ '</p></div>';



// output='<div class="col-md-4"><iframe id="youtube" src=\"//www.youtube.com/embed/'+videoId+'\"></iframe><p onclick="myFunction()"><span tabindex ="0"> Try it</span></p></div>';
// v = '<iframe class ="display" src=\"//www.youtube.com/embed/'+videoId+'\"></iframe>';
textout= videoDescription;
//append to results listStyleType
$('#results').append(output2);
// $('#myDIV').append(v);
$('#text').append(textout);
})


}
);
}

});

</script>
</body>
</html>
jquery html css iframe youtube

最佳答案

您是否尝试过渲染按钮,以便在单击时更新视频链接?看起来链接没有在点击时更新,这就是为什么您只看到相同的视频。

有点像...

var button = $("<button></button>")
.text("Add to Watchlist")
.click(function() {
getVids(pid)
render();
})

进入 render() 的是生成对 youtube 的请求的代码。 (即.get)

然后要添加按钮,我会将其附加到 div,与 div 行所在的位置相同。

$('#myDIV').append(button)

关于jquery - 如何让我的 div 显示选定的 youtube api 内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39682417/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com