【问题标题】:Connecting href from another div to src将 href 从另一个 div 连接到 src
【发布时间】:2014-09-29 19:29:23
【问题描述】:

我确实有一个问题,我正在尝试制作一个视频 iframe 弹出窗口来显示点击的视频。

这是包含视频的 div;

<ul class="video_list">
      <?php
        $result_video = mysqli_query($con,"SELECT * FROM guestlist_tvs ORDER BY created DESC LIMIT 16");
        while($row = mysqli_fetch_array($result_video)) { 
      ?>
        <li rel='<?php echo $row['video_music_cat'];?>' cat='<?php echo $row['video_cat'];?>'>
        <div class="testtest">
          <a href='http://www.youtube.com/embed/<?php echo $row['youtube_id']; ?>?rel=0&amp;wmode=transparent' class='video_thumb'>
            <div class="video_img_wrapper"><img class='video_img'src="http://img.youtube.com/vi/<?php echo $row['youtube_id']; ?>/maxresdefault.jpg" width='240px' height='160px'>
            <img class="play_button" src="images/play_button.png" alt="play" /></img></div>
            <h3><?php echo $row['title']; ?></h3>
          </a>
         </div>
        </li>
      <?php 
        }
        mysqli_close($con);
      ?>
      </ul>

iframe-popup 有这个代码:

<iframe width="854" height="480" src="MYVIDEOLINKHERE" frameborder="0" allowfullscreen></iframe>

我想弄清楚的是如何说 iframe 的 src 是“testtest”类的 href。

提前致谢

【问题讨论】:

  • 我认为你应该使用 jQuery。
  • 你能举个例子吗?
  • 您使用什么 API 创建对话框?
  • 我用了这个例子; afs.org/help/snippets/popup-video
  • 请出示您已有的javascript代码。

标签: php html href src


【解决方案1】:

我的解决方案是使用 jquery 和点击事件

$(document).ready(function() {  
    $('.video_thumb').click(function () {
        alert(this.getAttribute("src"));
    });

});

JSFIDDLE DEMO

【讨论】:

    【解决方案2】:

    在该页面的脚本标记中使用此 jquery

     $(document).ready(function(){
    
      $(".play_button").click(function(){
         $("iframe").attr("src") =$(this).closest(".testtest").find("a").first().attr("href");
    
    
    
    
      });
    
    
    
    
    
     });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-03-14
      • 1970-01-01
      • 1970-01-01
      • 2020-09-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-01
      相关资源
      最近更新 更多