将src属性传递给循环中的iframe

i am passing source attribute to iframe from source Array that is consisting URL of different videos. but the problem is iframe take only first index of source array in each alteration of loop. Code is given below.

<script language="javascript" type="text/javascript">
$(function(){
    $('.close').click(function(){      
        $('iframe#myVideo1aV').attr('src', $('iframe#myVideo1aV').attr('src'));

    });
});
</script>

    <?php     $src=array("http://player.vimeo.com/video/182048025","http://www.youtube.com/embed/L7ZQ0o1Gp5Y","http://player.vimeo.com/video/182048025");

        $sq = "Select * from videos_topics;
        $result = $con->query($sq);
        while ($row = $result->fetch_assoc()) {?>
        <div class="input-group">

        <button class="" data-toggle="modal" data-target="#Modal" ><?php 
         echo $row['video'] ;?></button>
        </div>

        <div class="modal"  id="Modal" role="dialog">
           <div class="modal-dialog modal-dialog-centered" role="document">
             <div class="modal-content" style="background-color:black">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"></button>
                    <div class="modal-body">
                        <iframe id="myVideo1aV" width="100%" height="400" <?php echo 'src="'.$src[$i].'" ';?>frameborder="0" allowfullscreen></iframe>
                    </div>

            </div>
        </div>
    </div>
    <?php  
     $i++;
    }?>
dsgdf45654
dsgdf45654 “但问题是iframe在循环的每次改变中只采用源数组的第一个索引-它真的是吗?”检查由脚本输出的生成的HTML源代码。
一年多之前 回复
dongpan5289
dongpan5289 干草@misorude我编辑了代码请再次检查。
一年多之前 回复
duanping2809
duanping2809 那么实际的循环在哪里呢?如果要输出已在循环中显示的整个HTML块,那么您将创建重复的ID,这在HTML中是不允许的,因此这是您需要修复的第一件事。并且没有关于src=“srcArray[index]”的动态,这只是一个src属性,指的是静态的“urL”srcArray[index]
一年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问