我有以下要求:
YouTube帖子会在发布YouTube广告网址时自动嵌入帖子中
有人可以给我一个启动器吗?
答案 0 :(得分:1)
我已经更改了多个网址,试试这个
</head>
<body>
<div class="condent">Lorem Ipsum is simply dummy text of the printing and http://www.youtube.com/watch?v=8YUmZNJUAHk No typesetting http://www.youtube.com/watch?v=8YUmZNJUAHk industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
var textContent = $('.condent').text();
var str1 = textContent.split(' ');
for (var i = 0, il = str1.length; i < il; i++) {
if (str1[i].indexOf("http://www.youtube.com/watch?v=") >= 0){
var youtubeURL = str1[i];
var youtubeId = youtubeURL.replace('http://www.youtube.com/watch?v=',"");
var embedCode = '<iframe width="560" height="315" src="//www.youtube.com/embed/'+youtubeId+'" frameborder="0" allowfullscreen></iframe>';
textContent = textContent.replace(youtubeURL,embedCode);
}
}
$('.condent').html(textContent);
});
</script>
</body>