admin管理员组文章数量:1287258
i am trying stuff with philogl library, and when i wrote,
<!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>
everything works fine, but if i write some philogl in it like,
<!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>
chrome and firefox gives me an error that says webGLStart() is not defined. What is wrong with my code?
i am trying stuff with philogl library, and when i wrote,
<!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>
everything works fine, but if i write some philogl in it like,
<!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>
chrome and firefox gives me an error that says webGLStart() is not defined. What is wrong with my code?
Share Improve this question edited Feb 25, 2011 at 13:01 cHao 86.6k20 gold badges146 silver badges177 bronze badges asked Feb 25, 2011 at 13:00 gkaykckgkaykck 2,36711 gold badges35 silver badges52 bronze badges 2- Beside Pointy's answer I remend Firebug (an add-on for Firefox), it shows many things about JavaScript, and helps you finding what you messed up. – Albireo Commented Feb 25, 2011 at 13:07
- sorry but the main problem is i have to use chrome for now because firefox is right now lacks support of webGL, and even v4b11 does gives me errors on every webgl demo's website, if there were any good standalone app for this... – gkaykck Commented Feb 25, 2011 at 13:50
2 Answers
Reset to default 8This line:
colors: [[0.5,0.5,1,1],[0.5,0.5,1,1]],[0.5,0.5,1,1]
is syntactically incorrect: a closing "]" is in the wrong place. Thus the function definition "failed", so to speak, and the function doesn't really exist.
I literally just woke up so I'm not sure what's wrong with me that I could spot that.
There must be an error in the way you are using this "philogl", preventing the function from being interpreted fully. In particular, you have a syntax error with your square brackets. The function then remains undefined.
In future you can turn on the error console in Firebug (or the equivalent for your preferred browser) to see what you're doing wrong.
Also, prefer document.onload = function() { ... }
in a script, instead of embedding scripting in HTML tags.
本文标签: javascriptbody onloadquotquot cannot find functionStack Overflow
版权声明:本文标题:javascript - body onload="" cannot find function - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741261435a2367699.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论