2013-12-04 9 views

ответ

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> 

+0

Проблема с вышеприведенным кодом заключается в том, что, когда я помещаю 2 или более ссылки на YouTube, он ломается, и если есть дополнительные параметры, добавленные в URL-адрес, он также сломается. – Chanakya

+0

Я изменил код с одного URL на несколько URL-адресов. приведенный выше код –

Смежные вопросы