我試圖用philogl庫的東西,當我寫,身體的onload =「」找不到功能
<!DOCTYPE html>
<html>
<head>
<title>PGL2</title>
<script type="text/javascript" src="PhiloGL.js"></script>
<script type="text/javascript">
function webGLStart(){
alert('I m alive');
}
</script>
</head>
<body onload="webGLStart();">
<canvas id="c" style="width:500px; height:500px;"></canvas>
</body>
</html>
一切工作正常,但如果我寫它像一些philogl,
<!DOCTYPE html>
<html>
<head>
<title>PGL2</title>
<script type="text/javascript" src="PhiloGL.js"></script>
<script type="text/javascript">
function webGLStart(){
var triangle = new PhiloGL.O3D.Model({
vertices: [[0,1,0],[-1,-1,0],[1,-1,0]],
colors: [[1,0,0,1],[0,1,0,1],[0,0,1,1]]
});
var square = new PhiloGL.O3D.Model({
vertices: [[1,1,0],[-1,1,0],[1,-1,0],[-1,-1,0]],
colors: [[0.5,0.5,1,1],[0.5,0.5,1,1]],[0.5,0.5,1,1]
});
}
</script>
</head>
<body onload="webGLStart();">
<canvas id="c" style="width:500px; height:500px;"></canvas>
</body>
</html>
鉻和Firefox給我一個錯誤,說webGLStart()沒有定義。 我的代碼有什麼問題?
旁邊[Pointy的回答](http://stackoverflow.com/questions/5117536/body-onload-cannot-find-function/5117571#5117571)我推薦[Firebug](http://getfirebug.com/) (Firefox的附加組件),它顯示了許多關於JavaScript的內容,並幫助您找到混亂的東西。 – Albireo 2011-02-25 13:07:37
不好意思,但主要的問題是我現在不得不使用chrome,因爲現在firefox缺乏對webGL的支持,甚至v4b11在每個webgl演示的網站上都會給我提供錯誤,如果有任何好的獨立應用程序... – gkaykck 2011-02-25 13:50:02