【发布时间】:2014-01-19 11:08:58
【问题描述】:
我在这段代码中找不到错误。该代码用于根据用户的输入使用画布绘制图形。它给我带来了 2 个错误:
Uncaught TypeError: undefined is not a function canvas.html?option=circulo:14
未捕获的类型错误:无法调用 null 的方法 'getContext'
var my_canvas = document.getElementById("a");
var con = my_canvas.getContext("2d");
var check = function(){
if((document.getElementById('opcion').value) === 'circulo'){
con.beginPath();
con.arc(75, 75, 20, 0, 2*Math.PI);
con.closePath();
}else if((document.getElementById('opcion').value) === 'rectangulo'){
con.strokeRect(100,100,20,50);
}else if((document.getElementById('opcion').value) === 'arcos'){
con.beginPath();
con.arc(75,75,35,0,Math.PI);
con.stroke();
}else{
alert("Ha ingresado un valor invalido");
}
};
【问题讨论】:
标签: javascript html canvas