1

我目前正在使用 html5 样板,它将 jQuery 和您的插件放入页脚。唯一的问题是,我在每个页面中使用相同的 footer.php 文件。如果插件还没有加载,我该如何去包含页面特定的功能?IE

<?php include_layout_template('header.php', '../');?>
<div id='mediaspace'>This text will be replaced</div>

<!-- Video for this page: -->

<script type='text/javascript'>
  jwplayer('mediaspace').setup({
  'flashplayer': '../resources/player.swf',
  'file': 'http://content.longtailvideo.com/videos/flvplayer.flv',
  'controlbar': 'bottom',
  'width': '470',
  'height': '320'
});
</script>

<?php //This file has the jwplayer function in it: 
include_layout_template('footer.php', '../'); ?>

这样做我得到

Uncaught ReferenceError: jwplayer is not defined 

将插件包含在标题中会更容易吗?人们通常如何在最后的样板/加载脚本中处理这样的事情?

4

2 回答 2

1

您是否尝试过 document.onready() 功能?这样脚本将在页面准备好后触发。

于 2012-06-06T10:44:36.403 回答
0

The “jwplayer is not defined” ReferenceError is exactly what it says it is. Your jwplayer reference is being called before your jwplayer.js file is loaded, which defines your jwplayer function.

If you can’t move the jwplayer.js file to the head of your document (so it’s loaded before you call jwplayer()), then you need to rethink how and when this script will be called.

I’m assuming the ‘mediaspace’ is referencing the id of an object/div? If so, leave that in the middle of the page where it belongs, and move the script below the footer.php include.

于 2012-06-06T13:36:29.913 回答