JS in the element (picture) Toggle and hide display problems

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.