admin管理员组文章数量:1317894
I set the function called "drawEverything()" to run onload, however the function doesn't run and I get a bug in Firebug saying "drawEverything is not defined"?? Thing is, I did define it!
I googled the problem and most of the time it was due to some kind of syntax error, but I've looked all over it and can't find any syntax errors.
My code is as follows:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test</title>
<link rel=stylesheet href="style.css" type="text/css">
</head>
<script type="text/javascript">
var new_x = 110;
var new_y = 150;
function drawEverything(){
var temp_x = new_x;
var temp_y = new_y;
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
for (int i = 0; i < 5; i++){
ctx.beginPath();
ctx.arc(temp_x,temp_y,20,0,2*Math.PI);
ctx.stroke();
if ((i < 3) || (i == 4)){
temp_x += 40;
}
else if (i == 3){
temp_y += 20;
temp_x -= 60;
}
}
}
</script>
<body onload = "drawEverything()">
<h1>Interactive Olympic Rings</h1>
<div id="container">
<canvas id="myCanvas" width="300" height="300"></canvas>
</div>
</body>
</html>
Any help would be appreciated, thanks!
I set the function called "drawEverything()" to run onload, however the function doesn't run and I get a bug in Firebug saying "drawEverything is not defined"?? Thing is, I did define it!
I googled the problem and most of the time it was due to some kind of syntax error, but I've looked all over it and can't find any syntax errors.
My code is as follows:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test</title>
<link rel=stylesheet href="style.css" type="text/css">
</head>
<script type="text/javascript">
var new_x = 110;
var new_y = 150;
function drawEverything(){
var temp_x = new_x;
var temp_y = new_y;
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
for (int i = 0; i < 5; i++){
ctx.beginPath();
ctx.arc(temp_x,temp_y,20,0,2*Math.PI);
ctx.stroke();
if ((i < 3) || (i == 4)){
temp_x += 40;
}
else if (i == 3){
temp_y += 20;
temp_x -= 60;
}
}
}
</script>
<body onload = "drawEverything()">
<h1>Interactive Olympic Rings</h1>
<div id="container">
<canvas id="myCanvas" width="300" height="300"></canvas>
</div>
</body>
</html>
Any help would be appreciated, thanks!
Share Improve this question asked Dec 9, 2012 at 11:49 Cloud StrifeCloud Strife 992 gold badges2 silver badges7 bronze badges 1- 4 You have your script in the twilight zone, between the head and the body, where nothing can exist! – adeneo Commented Dec 9, 2012 at 11:53
2 Answers
Reset to default 5Deal with your errors in order. Later errors can be a consequence of earlier one.
First error (as reported by firebug):
SyntaxError: missing ; after for-loop initializer
[Break On This Error]
for (int i = 0; i < 5; i++){
Second error:
ReferenceError: drawEverything is not defined
Since the function definition has pile time errors in it, it is not defined when you e to run it.
You want var
not int
.
You cannot use int here. Use var in javascript
本文标签: htmljavascript function not definedStack Overflow
版权声明:本文标题:html - javascript function not defined - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742037389a2417374.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论