일부 코메 시안 코드의 메소드로 사용되는 Javascript 클래스로 어려움을 겪고 있습니다.이 코드의 생성자는 어떻게 갖춰야합니까? 다음 코드는 유효하지 않습니다getElementById의 결과가 null입니까?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<link rel="Stylesheet" href="gStyle.css" />
<script type="text/javascript" language="javascript">
// Gantt chart object
function ganttChart(gContainerID) {
this.isDebugMode = true;
this.gContainer = document.getElementById(gContainerID);
if (this.isDebugMode) {
this.gContainer.innerHTML += "<div id=\"gDebug\">5,5 | 5.1</div>";
}
}
var myChart = new ganttChart("chart1");
</script>
</head>
</html>
<body>
<div id="chart1" class="gContainer"></div>
</body>
</html>
this.gContainer 페이지가 준비되기 전에 당신이 new ganttChart("chart1");
를 호출 할 때 즉 chart1
아직 존재하지 않는, 스크립트를 실행하기 때문에 즉
가능한 중복 (http://stackoverflow.com/questions/8739605/getelementbyid-returns-null) –