【问题标题】:.play(function (){ }); jquery not working.play(函数 (){ }); jQuery不工作
【发布时间】:2016-03-06 01:34:15
【问题描述】:

我希望播放视频后立即出现一个功能。我有以下代码,但它不起作用。

$(".jw-video")[0].play(function (){
  var link = $(".jw-video").attr("src");
  console.log(link);
});

请帮忙。

【问题讨论】:

  • 控制台有错误吗?为什么你认为它会起作用?
  • 或许可以试试:$(".jw-video")[0].live('playing', function(){ var link = $(".jw-video").attr("src"); console.log(link); });
  • @sscotti .live 已过时,已被删除一段时间。加上[0] 表示它可能不是 jQuery 对象。
  • 控制台没有错误
  • 您是否尝试使用 JWPlayer 插件?

标签: jquery function


【解决方案1】:

做了一些研究。这似乎可行,尽管可能有比直接混合和匹配 JS 和 jQuery 更好的方法,并且可以稍微清理一下,但它似乎可行。这是一个非常有用的链接:

W3 Org Video Media Events

JS/jQuery

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<script type="text/javascript">


$(function() {
videoElement = $(".jw-video")[0];
videoElement.addEventListener("playing", playHandler, false);
function playHandler(e) {
    alert("playing");
  var link = $(".jw-video")[0].currentSrc;
  console.log(link);
}
});
</script>

HTML

<video class="jw-video" width="320" height="240" controls>
<source id="mp4" src="test.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>

【讨论】:

  • 不知道为什么 $(".jw-video")[0].controller 返回 null ?不在代码中,但我想看看它是如何工作的。
猜你喜欢
  • 2014-10-17
  • 1970-01-01
  • 2021-06-30
  • 2020-01-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-04-21
  • 1970-01-01
相关资源
最近更新 更多