2016-03-26 4 views
0

Summernoteテキストエリアの変更YouTubeのURLを使用してDIV要素にIFRAMEを追加:は、このコードを使用してにはJavaScript

$video = $('<iframe>') 
     .attr('src', '//www.youtube.com/embed/' + youtubeId) 
     .attr('width', '640').attr('height', '360'); 

、それはこのにYouTubeのURLを回す:

<iframe src="//www.youtube.com/embed/_qxxxxxxc" width="640" height="360" frameborder="0"></iframe> 

が、私は、ブートストラップを挿入したいですこのように終了します:

<div class="embed-responsive embed-responsive-16by9"> 
<iframe class="embed-responsive-item" src="//www.youtube.com/embed/_qxxxxxxc" frameborder="0"></iframe> 

このようなジャバスクリプト:

$video = 
    $('<div>').attr('class','embed-responsive embed-responsive-16by9'); 
    $('<iframe>') 
    .attr('class', 'embed-responsive-item') 
    .attr('src', '//www.youtube.com/embed/' + youtubeId) 
    .attr('width', '640').attr('height', '360'); 

し、それが結果として、このように終わる:IFRAMEを維持し、DIV要素を追加する方法

<div class="embed-responsive embed-responsive-16by9" frameborder="0"></div> 

?ありがとうございました。

答えて

2

あなたの問題この

$video =  
    $('<iframe>') 
    .attr('class', 'embed-responsive-item') 
    .attr('src', '//www.youtube.com/embed/' + youtubeId) 
    .attr('width', '640').attr('height', '360'); 

$div = $('<div class="embed-responsive embed-responsive-16by9"></div>').append($video); 

を試してみては

$video = 
    $('<div>').attr('class','embed-responsive embed-responsive-16by9'); //the semicolon indicates end of line. So your $video ends here 

//below line of code does nothing. It just creates a iframe with all mentioned stuff and then???? its not put into any use. 
    $('<iframe>') 
    .attr('class', 'embed-responsive-item') 
    .attr('src', '//www.youtube.com/embed/' + youtubeId) 
    .attr('width', '640').attr('height', '360'); 
+0

あなたのコードの作品、BROました!それは '

'のように終わり、 'frameborder =" 0 "'はiframeではなくdiv要素に固執するようになりました。 –

+0

構文で 'frameborder =" 0 "'は表示されません。他のスクリプトを追加していると思います。あなたは確認できますか? –

+0

私はチェックしておきますが...他のスクリプトを追加しました。 –

関連する問題