I have never noticed that $ ("# air") in jquery is the same thing as document. getelementbyid ("Air"). It refers to the same thing. Write a canvasProgramThe two are different.
Directly use alert () to show what the two methods actually obtain.CodeAs follows:
<! Doctype html >
< Html >
< Head >
< Meta Charset = "UTF-8" >
< Title > Air </ Title >
< Link Href = "CSS/index.css" REL = "Stylesheet" Type = "Text/CSS" >
< Script SRC = "JS/jquery-1.4.2.min.js" Type = "Text/JavaScript" > </ Script >
</ Head >
< Body >
< Div Class = "Warp" >
< Canvas ID = "Air" > </ Canvas >
</ Div >
< Script >
VaR Canvas_air = $ ( " # Air " );
Alert (canvas_air );
Alert (document. getelementbyid ("Air "));
VaR Air_2d = Canvas_air.getcontext ( " 2d " );
VaR Air_img = New Image ();
Air_img.src = " Images/Boston-III-48px.png " ;
Air_2d.drawimage (air_img, 0 , 0 );
</ Script >
</ Body >
</ Html >
The Alert () values are [object] and [object htmlcanvaselement]. From here, it is not hard to see that $ ("# air") is not as expected. Let's take a look at firebug debugging,
$ ("# Air") and document. getelementbyid ("Air. The debugging result is as follows:
$ ("# Air") [Canvas # air]
Document. getelementbyid ("Air") Canvas # air
You may think of the results as well.
In fact, $ ("# air") [0] is equivalent to document. getelementbyid ("Air ")