我需要为我的博客(博主)提供有效代码才能使用以下字符串获取YouTube视频标题:
" http://gdata.youtube.com/feeds/api/videos/EDV-KMBvMck?v=2&alt=json&prettyprint=true"
(此字符串在Internet Explorer中运行良好)
我在这里找到了各种方法,但没有显示结果。
我想在td标签内显示视频的标题。
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<style>
table#t01 {
width: 100%;
}
table#t01,
th,
td {
border: 1px solid black;
border-collapse: collapse;
text-align: center;
}
</style>
</head>
<body>
<div>
<table id="t01">
<col style="width:50%;">
<col style="width:50%;">
<tr>
<td>
<a href="http://www.youtube.com/embed/EDV-KMBvMck" target="_blank"><img src="https://img.youtube.com/vi/EDV-KMBvMck/default.jpg"" alt="YouTube Icon"></a>
</td>
<td>
<script>
$Video_Id = 'EDV-KMBvMck'
$.getJSON("http://gdata.youtube.com/feeds/api/videos/{$Video_Id}?v=2&alt=json&prettyprint=true", function(json) {
console.log("success");
var items = [];
$.each(json. {
$Video_Id
}, function(key1, val1) {
$Value = val1.key + val1.val
});
echo $Value
})
.done(function() {
console.log("second success");
})
.fail(function() {
console.log("error");
})
.always(function() {
console.log("complete");
})
.error(function(error) {
console.log(error);
});
</script>
</td>
</tr>
<tr>
<td>
<a href="http://www.youtube.com/embed/yXL7dT7ovEM" target="_blank"><img src="https://img.youtube.com/vi/yXL7dT7ovEM/default.jpg"" alt="YouTube Icon"></a>
</td>
<td>
<script>
$Video_Id = 'yXL7dT7ovEM'
$.getJSON("http://gdata.youtube.com/feeds/api/videos/{$Video_ID}?v=2&alt=json&prettyprint=true", function(json) {
console.log("success");
var items = [];
$.each(json. {
$Video_Id
}, function(key1, val1) {
$Value = val1.key + val1.val
});
echo $Value
})
.done(function() {
console.log("second success");
})
.fail(function() {
console.log("error");
})
.always(function() {
console.log("complete");
})
.error(function(error) {
console.log(error);
});
</script>
</td>
</tr>
</table>
</div>
</body>
</html>
&#13;
我想在标题中使用一个函数,它会在每次更改Video_Id时从td标记调用。
答案 0 :(得分:0)
<iframe title="YouTube video player" class="youtube-player" type="text/html" width="640" height="390" src="http://www.youtube.com/embed/W-Q7RMpINVo" frameborder="0" allowFullScreen></iframe>
将其粘贴到您的网页中并进行必要的更改。它适用于Firefox,MSIE,Chrome,Opera以及任何新的浏览器。