Timesheet.js没有发起

时间:2014-12-17 11:03:49

标签: javascript jquery html5 css3

我正在努力让Timesheet.js工作,我最初想在Wordpress网站上运行,但没有运气,所以将它完全剥离回一个普通的html文件。这是我的代码:

<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<link href="timesheet.css" rel="stylesheet" type="text/css" />
<script src="timesheet.js" type="text/javascript" /></script>

<script type="text/javascript">     
new Timesheet('timesheet', 2002, 2013, [
  ['2002', '09/2002', 'A freaking awesome time', 'lorem'],
  ['06/2002', '09/2003', 'Some great memories', 'ipsum'],
  ['2003', 'Had very bad luck'],
  ['10/2003', '2006', 'At least had fun', 'dolor'],
  ['02/2005', '05/2006', 'Enjoyed those times as well', 'ipsum'],
  ['07/2005', '09/2005', 'Bad luck again', 'default'],
  ['10/2005', '2008', 'For a long time nothing happened', 'dolor'],
  ['01/2008', '05/2009', 'LOST Season #4', 'lorem'],
  ['01/2009', '05/2009', 'LOST Season #4', 'lorem'],
  ['02/2010', '05/2010', 'LOST Season #5', 'lorem'],
  ['09/2008', '06/2010', 'FRINGE #1 & #2', 'ipsum']
]);
</script>

<div id="timesheet" class="timesheet color-scheme-default"></div>

这是我试过的page。很确定这是supplied files的问题,而不是我做错了什么?

1 个答案:

答案 0 :(得分:1)

在运行代码时,似乎没有准备好DOM。你可以做几件事:

移动此代码:

<div id="timesheet" class="timesheet color-scheme-default"></div>

在你的上方:

<script type="text/javascript">     
    new Timesheet(...);
</script>

或者将代码包装在jQuery(document).ready(function () { ... });中,如下所示:

<script type="text/javascript">
jQuery(document).ready(function () {     
    new Timesheet(...);
});
</script>