This knowledge point in fact is also simple, (of course, in the case of clear thinking), in the case of no preview of the situation is really difficult to listen to, the only time since the first day of confusion, feeling chaotic, all is a new attribute, so tonight's my first night to knock code, must understand!
Now, let's comb the dots:
1, the body inside the elements or pictures first built, in we need to add some special effects, this time we need to use the DOM object Model JS;
First get the elements on the page that need to add special effects, there are three ways, namely: ID (document.getElementById ()) tag (Document.getelementbytagname ()) class name (Document.geteleme Ntbyclassname ()). However, the class name has browser compatibility issues, generally not, unless the label style requires special handling.
2 Event Handling
This step to the previous acquisition of the elements of special effects processing, this time need to use the function; There are two types of registration events, inline and embedded, the feeling of the inside of the property will be a bit chaotic, (personal feeling), embedded words concise and clear, a look at understand. Here's an example:
Inline type:
<body>
<Ahref="Images/1.jpg"><ImgSrc="Images/1-small.jpg"></A>
<Ahref="Images/2.jpg"><ImgSrc="Images/2-small.jpg"></A>
<Ahref="Images/3.jpg"><ImgSrc="Images/3-small.jpg"></A>
<a href= "images/4.jpg" ><img src= "Images/4-small.jpg" ></a>
Span style= "color: #f7f7f1;" ><a href= "images/ 5.jpg "><img src = "images/5-small.jpg" ></ a>
<script>
img=document. getElementById("img";);
links=document. getElementsByTagName("a";
For(VarI=0;I<links.Length;i++) {){
VarLink=links[ i link.onclick=function () { img.src=this.href return false;
}
};
} /span> </script>
</body>
In-line:
</Head>
<Body>
<Ahref="Images/1.jpg"onclick="Turn(This);return False;"Id="A1"><ImgSrc="Images/1-small.jpg"></A>
<Ahref="Images/2.jpg"onclick="Turn(This);return False;"Id="A2"><ImgSrc="Images/2-small.jpg"></A>
<Ahref="Images/3.jpg"onclick="Turn(This);return False;"Id="A3"><ImgSrc="Images/3-small.jpg"></A>
<Ahref="Images/4.jpg"onclick="Turn(This);return False;"Id="A4"><ImgSrc="Images/4-small.jpg"></A>
<Ahref="Images/5.jpg"onclick="Turn(This);return False;"Id="A5"><ImgSrc="Images/5-small.jpg"></A>
<ImgSrc="Images/placeholder.png"Id="IMG"Width="600">
<Script>
Varimg=Document.getElementById("IMG");
function turn (link) { img< Span style= "color: #ffffff;" >. src=. href
};
</script>
The above is the focus of today's study, more knock several times, slowly add it!
JS in the element (picture) Toggle and hide display problems