Now there are fewer and fewer people who use JavaScript. More people like jquery, but I still like JavaScript. Below is a small example of background switching written in JavaScript, don't scold me, just write it for yourself. It also serves as the basis for the Production Test of JS events.
HTML code
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> <HTML xmlns =" http://www.w3.org/1999/xhtml ">
Because the Javascript logic sequence is strong, consider referencing the JS location.
CSS code
Code
1 body {font-size:12px;}
2 div{ width:950px; height:800px; margin:0 auto; border:solid 1px #d0d0d0;}
3 li{ list-style-type:none;border:solid 1px #d0d0d0; float:left; margin: 1px; padding:0 5px; height:12px; width:10px;}
4 /*div{ width:6px; height:14px; margin:1px; padding:0 5px; float:left; border:solid 1px #d0d0d0;}*/
5
JavaScript code:
Code
1 window. onload = Init;
2 var element = Document. getelementsbytagname ("Li ");
3 function Init () // initialize the background color
4 {
5
6 var element = Document. getelementsbytagname ("Li ");
7 For (VAR I = 0; I <4; I ++)
8 {
9 var K = I + 1;
10 element [I]. style. Background = "URL (images/" + K. tostring () + ". jpg )";
11}
12}
13
14
15 function addclick ()
16 {
17 For (VAR I = 0; I <4; I ++)
18 {
19
20 var K = I + 1;
21
22 if (window. attachevent)
23 element [I]. attachevent ("onclick", new function ("bgchage (" + K + ");"); // you cannot directly create an event. onclick. attachevent ("Event", new function ("called function (" + parameter + ");"); IE6 passes
24 else
25 element [I]. addeventlistener ("click", new function ("bgchage (" + K + ");"), false );
26
27}
28}
29
30 function bgchage (t) // change the background color based on the Color Block
31 {
32 document. getelementsbytagname ("body") [0]. style. Background = "URL (images/" + T + ". jpg )";
33}
34
35 addclick ();
36
37
The JS part should pay attention to the compatibility of writing events. In fact, the idea of JQ is to write many functions into plug-ins for your own use. It can be written in JavaScript to write your own class libraries for repeated use, and does not need to bear the burden of jquery class libraries. In fact, I am not saying that jquery is not good. In the big aspect, jquery's plug-in size does not have a big impact. The front-end events saw the videos of Baidu's front-end exchange meetings, I found that all other class libraries are written by JS itself, which gave me the motivation to continue to learn about Js.