【问题标题】:object has no method setup jwplayer对象没有方法设置 jwplayer
【发布时间】:2013-05-28 17:37:15
【问题描述】:

我从jade调用这个javascript文件

-if ...

-else
  div#container
  script(type='text/javascript')
    jwplayer('container').setup({       

     file: '/path/to/file.m3u8',
     width: '0',
     height: '0'
    });

Uncaught TypeError: Object # has no method 'setup'

同样的 javascript 文件也在标头中。

【问题讨论】:

  • 你确定container是元素的id吗?
  • 是的,我实际上是在翡翠中,所以它是由 div#container 完成的

标签: javascript html pug jwplayer


【解决方案1】:

您需要将 pug 设置为纯文本模式,并在脚本标签末尾加上句点,否则它会尝试在其下方渲染更多 DOM 元素。 Script 不是 pug 中的保留字,它只是像任何其他 HTML 元素一样呈现它,并且 pug 不知道接下来是 JavaScript(这是 IMO 的一件好事)

在标签末尾添加句点告诉 pug 它应该将标签中包含的所有内容呈现为纯文本。如果你想在纯文本部分使用 pug 变量,你需要使用interpolation

这对你有用:

  script.
    jwplayer('container').setup({       

     file: '/path/to/file.m3u8',
     width: '0',
     height: '0'
    });

此外,您无需再在脚本元素上添加 type 属性 (details)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多