当 boostrap 模式在 jQuery 中可见时添加 iFrame

Adding an iFrame when a boostrap modal is visible with jQuery

本文关键字:添加 iFrame boostrap 模式 jQuery      更新时间:2023-09-26

当模态通过jQuery在屏幕上可见时,我想将youtube嵌入添加到模态中,因为我在屏幕上有多个模态会显着影响页面加载时间,我只想在屏幕上显示该特定模态时加载视频。

$( document ).ready(function() {
 $(modalID).on('show',function(){
       $('.player').html('<iframe width="560" height="315" src="embed code" frameborder="0" allowfullscreen></iframe>');//iframe class
});  
});

我想通了,让任何想知道的人......显然,您需要一个没有初始src属性的iFrame,例如宽度。高度=...和其余属性

    $( document ).ready(function() {
 $(modalID).on('show',function(){
       $(iFrame).attr('src', youtube embed src);//add the youtube embed source
});  
});