The first few blogs about the basis of jquery and click on the actual, the following, and CSS with how to do
Or as usual, for example.
Several squares, then set the color
<!DOCTYPE HTML Public "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/TR/xhtml1/DTD/ Xhtml1-transitional.dtd "><HTMLxmlns= "http://www.w3.org/1999/xhtml"><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8" /><title>Untitled Document</title><Scriptsrc= "Jquery-1.11.2.min.js"></Script><styletype= "Text/css">. AA{width:200px;Height:200px;float: Left;margin:5px;Background-color:#039}</style></Head><Body><Divclass= "AA"></Div><Divclass= "AA"></Div><Divclass= "AA"></Div><Divclass= "AA"></Div><Divclass= "AA"></Div><Divclass= "AA"></Div><Divclass= "AA"></Div><Divclass= "AA"></Div><Divclass= "AA"></Div><Divclass= "AA"></Div><Divclass= "AA"></Div><Divclass= "AA"></Div><Divclass= "AA"></Div><Divclass= "AA"></Div></Body></HTML>
By the way, review the knowledge of CSS
Give the. AA plus the style width 200 pixels high 200 pixels left flow distance 5 pixel color casually set, here is the blue
Look at the effect of running a run
Probably so, Div set a few are OK
Make it perform every click to change color
If you use JS to do, write a lot of code, so choose the jquery method to do
Take a look at the jquery code section
First find the. AA Click Plus event, inside the $ (this) is found click on who and then give him CSS background color
Look at the effect of the run
Click on which block will turn red.
But we have to get it back again, so we have to add the jquery code.
Only need to add a line of code on it, the two lines of code, the meaning is that when you click on the background color will become red, the other is the original background color, here to pay attention to the original background color to the top set background color consistent
Take a look at the effect
Click which block, which turns red, when the other block, the previous block will become the original background color
In addition to a click event, there is an event that can be triggered when the mouse is moved up.
The code can take a look
Temporarily put the Click Code Section annotated,. MouseMove the meaning of moving on
Just a change of code, the other code is the same
Have the intention to do a try, move on the event will not look at the effect, the picture can not be seen, the background color will follow the position of the mouse move changes
If both are implemented at the same time, you can also
Someone might think of this.
This will be a bug to write operations, so that the effect will be moved yellow, click on the mouse as long as not moving is red, but the mouse moves slightly, will immediately turn yellow
Take a look at the code's correct wording.
Add a property identifier to the Click event, then add a code after the event, attribute filter, find the element based on the property, set the background color
Look at the effect of the run
Click on a piece will turn red, the mouse movement in addition to the click of the block, the other will turn yellow
Jquery with CSS, simple and effective