var canvas = document.getElementById("canvas"); var canvas2 = $("#canvas") console.log(canvas, canvas2);调试看到的结果HTMLCanvasElement [<canvas id=?"canvas" width=?"100" height=?"100">?]
var cxt=c.getContext("2d");
Corrected to var cxt=c.get(0).getContext("2d"); or var cxt=c[0].getContext("2d");
Reason: Because what you get with jQuery("#myCanvas") is a jQuery object, but getContentx("2d") is a property of the DOM. So you need to convert it;
You They all asked and answered themselves.
It’s because one is a jQuery object and the other is a DOM object.
You can convert between them.
To change a jQuery object to a DOM object, use the get() method.
To change a DOM object to a jQuery object, use $()
What does that mean? .
What does it mean. .
You have asked and answered your own questions.
It’s because one is a jQuery object and the other is a DOM object.
You can convert between them.
To change a jQuery object into a DOM object, use the get() method.
To change a DOM object into a jQuery object, use $()
I just found the reason for the problem I just posted. Thank you two enthusiastic friends!