【发布时间】:2013-12-04 08:35:23
【问题描述】:
我有如下要求:
YouTube 链接应在发布 youtube 网址时自动嵌入帖子中
谁能给我一个开场白?
【问题讨论】:
-
谷歌嵌入你的管元素?
我有如下要求:
YouTube 链接应在发布 youtube 网址时自动嵌入帖子中
谁能给我一个开场白?
【问题讨论】:
我已经更改了多个网址,试试这个
</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>
【讨论】: