JWPlayer - undefined不是一个函数 [英] JWPlayer - undefined is not a function

查看:182
本文介绍了JWPlayer - undefined不是一个函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有人可以帮助我。

Im wondering if someone could help me out.

我尝试使用jwplayer加载视频但收到错误。

Im trying to load a video using jwplayer but am getting errors.

这是我正在使用的代码。

This is the code im using.

        <script type="text/javascript">
            jwplayer("legacyPlayer").setup({
                width:370,
                height:240,
                file: "https://s3.amazonaws.com/legacy/videoname.mp4",
            });
        </script>

        <div id="legacyPlayer" align="center"></div>

我的控制台显示的错误如下:

The error my console is showing is as follows:

Uncaught TypeError: undefined is not a function 

任何帮助实现这项工作将不胜感激。

Any help getting this working would be greatly appreciated.

干杯,

推荐答案

您应该在HTML标记之后放置脚本块,如下所示:

You should put script block after the HTML tag, looks like this:

<div id="legacyPlayer" align="center"></div>
<script type="text/javascript">
    jwplayer("legacyPlayer").setup({
        width:370,
        height:240,
        file: "https://s3.amazonaws.com/legacy/videoname.mp4",
    });
</script>

当浏览器文档解析器遇到脚本标记时,它将停止解析页面上的其他html内容,直到脚本已下载并执行。这意味着当您尝试在脚本块中操作它时,legacyPlayer不存在。这是未定义不是函数错误的根本原因(jwplayer选择器找不到具有ID的DOM:legacyPlayer)。

When browser document parser encounters a script tag, it will stop parsing the other html content on your page until the script is downloaded and executed. It means that "legacyPlayer" is not exist when you try to manipulate it in the script block. That's the root cause of "undefined is not a function" error (jwplayer selector can't find a DOM with ID:legacyPlayer).

这篇关于JWPlayer - undefined不是一个函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆