2014-01-22 13 views
0

我有這段代碼,我試圖通過jQuery生成這個塊。另外還有在html代碼中的flash腳本。從jQuery動態添加HTML和Flash對象

<div class="span4" style="margin-bottom: 30px; position: relative" > 
    <h5>Reverse Video for</h5> 
    <button class="modal-close pull-right">&times;</button> 
    <div id="student-video1" > 
    <script> 
     swfobject.embedSWF(swfLoader, "student-video1", "300", "200", 
     swfVersionStr, xiSwfUrlStr, flashvars, this.params, {id: 'student-video-object', name: 'student-video-object'}); 
    </script> 
    </div> 
</div> 

,我試圖在jQuery的

var div = $('<div class="span4" style="margin-bottom: 30px; position: relative" > 
       <h5>Reverse Video for</h5> 
       <button class="modal-close pull-right">&times;</button> 
       <div id="student-video1" > 
        <script> 
        swfobject.embedSWF(swfLoader, "student-video1", "300", "200", 
        swfVersionStr, xiSwfUrlStr, flashvars, this.params, {id: 'student-video-object', name: 'student-video-object'}); 
        </script> 
       </div> 
       </div>'); 

    $('.container').before(div); 

動態地注入這個divbutton的點擊我想我做錯了,因爲它不工作。有什麼建議麼 ?

+0

只是變種DIV刪除$()...... –

回答

5

您應該使用\escapemulti-line string一樣,

var div = $('<div class="span4" style="margin-bottom: 30px; position: relative">\ 
      <h5>Reverse Video for</h5>\ 
      <button class="modal-close pull-right">&times;</button>\ 
      <div id="student-video1" >\ 
       <script>\ 
       swfobject.embedSWF(swfLoader, "student-video1", "300", "200", swfVersionStr, xiSwfUrlStr, flashvars, this.params, {id: \'student-video-object\', name: \'student-video-object\'});\ 
       </script>\ 
      </div>\ 
      </div>'); 

$('.container').before(div); 
+0

你我的朋友是真棒,THX – Ajey