我正在从 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 文件也在标题中。
最佳答案
您需要将 pug 置于纯文本模式,并在脚本标记的末尾添加一个句点,否则它会尝试在其下方呈现更多的 DOM 元素。 Script 不是 pug 中的保留字,它只是像任何其他 HTML 元素一样呈现它,而 pug 不知道后面是 JavaScript(这是 IMO 的好事)
将句点添加到标记的末尾告诉 pug 它应该将标记中包含的所有内容呈现为纯文本。如果你想在纯文本部分使用 pug 变量,你需要使用 interpolation .
这对你有用:
script.
jwplayer('container').setup({
file: '/path/to/file.m3u8',
width: '0',
height: '0'
});
此外,您不需要再在脚本元素 ( details ) 上添加类型属性。
关于javascript - 对象没有方法设置 jwplayer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16798188/