我使用$(document).ready()
运行了下面给出的代码。问题是CATCH已执行且err.message
返回 g未定义。但是alert(g)
返回了对象。我不明白为什么对象 g 被删除得如此奇怪。请帮忙。
<script>
function createChartControl(htmlDiv) {
var g = new JSGantt.GanttChart('g',document.getElementById(htmlDiv), 'day');
g.setShowRes(1); // Show/Hide Responsible (0/1)
g.setShowDur(1); // Show/Hide Duration (0/1)
g.setShowComp(1); // Show/Hide % Complete(0/1)
g.setCaptionType('Resource'); // Set to Show Caption (None,Caption,Resource,Duration,Complete)
// Parameters (pID, pName, pStart, pEnd, pColor, pLink, pMile, pRes, pComp, pGroup, pParent, pOpen, pDepend, pCaption)
g.AddTaskItem(new JSGantt.TaskItem(1, 'Define Chart API', '', '', 'ff0000', 'http://help.com', 0, 'Brian', 0, 1, 0, 1));
g.AddTaskItem(new JSGantt.TaskItem(11, 'Chart Object', '7/20/2008', '7/20/2008', 'ff00ff', 'http://www.yahoo.com', 1, 'Shlomy', 100, 0, 1, 1));
g.AddTaskItem(new JSGantt.TaskItem(12, 'Task Objects', '', '', '00ff00', '', 0, 'Shlomy', 40, 1, 1, 1));
g.AddTaskItem(new JSGantt.TaskItem(121, 'Constructor Proc', '7/21/2008', '8/9/2008', '00ffff', 'http://www.yahoo.com', 0, 'Brian T.', 60, 0, 12, 1));
g.AddTaskItem(new JSGantt.TaskItem(122, 'Task Variables', '8/6/2008', '8/11/2008', 'ff0000', 'http://help.com', 0, 'Brian', 60, 0, 12, 1,121));
g.AddTaskItem(new JSGantt.TaskItem(123, 'Task by Minute/Hour', '8/6/2008', '8/11/2008 12:00', 'ffff00', 'http://help.com', 0, 'Ilan', 60, 0, 12, 1,121));
g.AddTaskItem(new JSGantt.TaskItem(124, 'Task Functions', '8/9/2008', '8/29/2008', 'ff0000', 'http://help.com', 0, 'Anyone', 60, 0, 12, 1, 0, 'This is another caption'));
g.AddTaskItem(new JSGantt.TaskItem(2, 'Create HTML Shell', '8/24/2008', '8/25/2008', 'ffff00', 'http://help.com', 0, 'Brian', 20, 0, 0, 1,122));
g.Draw();
g.DrawDependencies();
}
}
</script>
<script>
$(document).ready(function() {
createChartControl('schedule');
});
<div style="position:relative" class="gantt" id="schedule"></div>
更新:我应该说,如果我在没有$(document).ready()的情况下运行此代码 - 也就是说在DIV标签之后,那么它就可以了。怎么可能????
更新2:以下是转载项目:http://jsfiddle.net/Udkkv/4/它不起作用,但现在可能更容易提供帮助。
答案 0 :(得分:1)
var g在定义之前使用。问题出在您网站的.js文件中:&#34; http://www.jsgantt.com/jsgantt.js"。
if (vGroup != 1)
{
vStart = JSGantt.parseDateStr(pStart,g.getDateInputFormat());
vEnd = JSGantt.parseDateStr(pEnd,g.getDateInputFormat());
}
在上面的代码中,您尝试使用:
g.getDateInputFormat()
虽然var g仍未定义。