【问题标题】:Video Current time giving undefined视频当前时间未定义
【发布时间】:2016-12-11 19:30:50
【问题描述】:

您好,我有动态视频,我试图获取当前视频时间,但我似乎变得不确定,我不知道为什么。我使用 on time update javascript 事件触发了一个函数,但是当我提醒这个 var ok=$(e).attr('id');我得到了视频 ID,但我不知道为什么当我尝试获取视频当前时间时我得到未定义的值,这是我的代码不知道我在哪里弄错了。

      <script type='text/javascript'>
 function men(e){
    var ok = $(e).attr('id');
     var ol = $(e).attr('id');
    // alert(ol[0].currentTime); --- GIVES ME UNDEFINED
    $.ajax({
          type : 'POST',
           url : 'updatetime.php', 
          data :  {ok: ok, om: om}, 
            success : function(r)
           {

           }
    });
 }
 </script>

     <?php
$tl="channel";
$ooa="playing";
$played="played";
$timeline = mysqli_query($con, "SELECT * FROM plays WHERE streamers_type ='$tl' AND played !='$played' GROUP BY streamers_id ORDER BY id ASC") or die ();
    while($row = mysqli_fetch_array($timeline)) {
    $id = $row['id'];
    $file1 = $row['file1'];
    $video_name = $row['video_name'];
    $video_type = $row['video_type'];
    ?>  

  <video class="uopi spinal" id="<?php echo $id ?>"  style="height:180px; width:100%!important;" autoplay muted onended="run(this)" ontimeupdate="men(this)"><source src="plays/<?php echo $file1 ?>" type="<?php echo $video_type ?>"></video>

            <?php } ?>

【问题讨论】:

    标签: javascript jquery video


    【解决方案1】:

    你正在做的是

    var ol = $(e).attr('id');
    
    ol[0].currentTime;
    

    但是.attr('id')返回一个字符串,元素的ID,显然没有currentTime属性。

    试试看

    $(e)[0].currentTime
    

    改为

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-10-21
      • 2011-10-21
      • 1970-01-01
      • 1970-01-01
      • 2011-09-16
      • 2011-12-10
      • 1970-01-01
      • 2013-08-18
      相关资源
      最近更新 更多