dongyou4411 2016-01-19 18:05
浏览 117
已采纳

点击时使用jQuery或Javascript更改变量值

I have a page with a table of video links (think playlist) that each contain a vimeo id. I also have an HTML5 player that is optimized for Vimeo videos and I simply need to change the ID upon clicking on a selected video.

My code is as follows:

Video Player:

<?php 
    <iframe width="100%" height="520" frameborder="0" allowfullscreen="" mozallowfullscreen="" webkitallowfullscreen="" src="//player.vimeo.com/video/[ID-GOES-HERE]" id="myvideo"></iframe>
?>

My table is as follows:

<table width="100%">
    <tbody>
        <tr>
            <td valign="middle" class="media"><p><a href="#"><i class="fa fa-play-circle-o"></i></a></p></td>
            <td valign="middle" class="name"><p>Christmas Chapel<span>Dr William M Wilson</span></p></td>
            <td valign="middle" class="info"><p>Special Christmas Chapel</p></td>
            <td valign="middle" class="day"><p>December 02, 2015</p></td>
        </tr>
        <tr>
            <td valign="middle" class="media"><p><a href="#"><i class="fa fa-play-circle-o"></i></a></p></td>
            <td valign="middle" class="name"><p>Christmas Chapel<span>Dr William M Wilson</span></p></td>
            <td valign="middle" class="info"><p>Special Christmas Chapel</p></td>
            <td valign="middle" class="day"><p>December 01, 2015</p></td>
        </tr>
    </tbody>
</table>

I would like to have it so that when anyone clicks on the "a" tag for Dec 2nd it pushes that videos vimeo id into the player and starts autoplaying the video. It would also need to override the Dec 2nd value with Dec 1st if I click on that.

What is the best way of doing this?

  • 写回答

1条回答 默认 最新

  • douangzhao4108 2016-01-19 18:23
    关注

    If it were me, I would give the iframe an id to make it easier to reference. Then use jquery to change to src.

    <iframe id="myiframe" width="100%" height="520" frameborder="0" allowfullscreen="" mozallowfullscreen="" webkitallowfullscreen="" src="//player.vimeo.com/video/[ID-GOES-HERE]" id="myvideo"></iframe>
    
    <a href="#" class="thelinks" onclick="replace_src('ABC_THE_VIMEO_ID_XYZ');"><i class="fa fa-play-circle-o"></i></a>
    
    <script>
    function replace_src(vimeoid) {   $('#myiframe').attr("src", "http://player.vimeo.com/video/"+vimeoid); }
    </script>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 slam rangenet++配置
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊