Home > Web Front-end > HTML Tutorial > Questions for beginners to learn html5_html/css_WEB-ITnose

Questions for beginners to learn html5_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 12:11:41
Original
1008 people have browsed it

            var canvas = document.getElementById("canvas");            var canvas2 = $("#canvas")             console.log(canvas, canvas2);调试看到的结果HTMLCanvasElement [<canvas id=?"canvas" width=?"100" height=?"100">?]
Copy after login

Confused
Why are the elements obtained by jquery different from those obtained by document.getElementById?
Can I only use document.getElementById to create canvas?
Please give me some advice.


Reply to the discussion (solution)

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template