javascript为什么错误是TypeError: undefined is not a function
<!DOCTYPEhtml><html><head><scripttype="js/javascript"src="js/gameDraw.js"><...
<!DOCTYPE html>
<html>
<head>
<script type="js/javascript" src="js/gameDraw.js"></script>
<script>
(function () {
alert("help me !!!!!");
var gameDraw = new gameDraw("myCanvas");
alert("help me11111 !!!!!");
gameDraw.drawBall();
alert("help me2222 !!!!!");
})();
</script>
</head>
<body>
<canvas id="myCanvas" width="600" height="400">Your Broswer don't support html5 canvas<canvas>
</body>
</html>
接下来是js文件
function gameDraw(canvas){
var canvasX,canvasY,ballX,ballY;
var ctx = document.getElementById(canvas).getContext("2d");
function upDate(){
this.drawBall();
this.drawCue();
};
function drawBall(){
this.drawArc(200,200,8);
};
function drawCue(){
this.drawRect(150,120,200,130)
};
function drawArc(certerX,certerY,R){
cxt.fillStyle="#000000";
cxt.beginPath();
cxt.arc(certerX,certerY,R,0,Math.PI*2,true);
cxt.closePath();
cxt.fill();
};
function drawRect(leftTopX,leftTopY,rightLowX,rightLowY){
cxt.fillStyle="#FF0000";
cxt.fillRect(leftTopX,leftTopY,rightLowX,rightLowY);
};
}; 展开
<html>
<head>
<script type="js/javascript" src="js/gameDraw.js"></script>
<script>
(function () {
alert("help me !!!!!");
var gameDraw = new gameDraw("myCanvas");
alert("help me11111 !!!!!");
gameDraw.drawBall();
alert("help me2222 !!!!!");
})();
</script>
</head>
<body>
<canvas id="myCanvas" width="600" height="400">Your Broswer don't support html5 canvas<canvas>
</body>
</html>
接下来是js文件
function gameDraw(canvas){
var canvasX,canvasY,ballX,ballY;
var ctx = document.getElementById(canvas).getContext("2d");
function upDate(){
this.drawBall();
this.drawCue();
};
function drawBall(){
this.drawArc(200,200,8);
};
function drawCue(){
this.drawRect(150,120,200,130)
};
function drawArc(certerX,certerY,R){
cxt.fillStyle="#000000";
cxt.beginPath();
cxt.arc(certerX,certerY,R,0,Math.PI*2,true);
cxt.closePath();
cxt.fill();
};
function drawRect(leftTopX,leftTopY,rightLowX,rightLowY){
cxt.fillStyle="#FF0000";
cxt.fillRect(leftTopX,leftTopY,rightLowX,rightLowY);
};
}; 展开
1个回答
展开全部
这个问题是因为你调用的函数未定义;不过没有看到你的具体代码,你可能是以下情况:
1、的确是没有定义这么一个函数;
2、定义函数了,但是在你调用的时候,你的函数并没有初始化。
<script>
(function () {
alert("help me !!!!!");
var gameDraw = new gameDraw("myCanvas");
alert("help me11111 !!!!!");
gameDraw.drawBall();
alert("help me2222 !!!!!");
})();
</script>
改为
<script>
window.onload=function() {
alert("help me !!!!!");
var gameDraw = new gameDraw("myCanvas");
alert("help me11111 !!!!!");
gameDraw.drawBall();
alert("help me2222 !!!!!");
}
</script>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询