Example of js conversion to display images

Source: Internet
Author: User

Start Interface

Copy codeThe Code is as follows: <Title> </title>
<Script type = "text/javascript">
Function UpdateImg (){
// Document. getElementById ('img1'). setAttribute ('src', 'images/2.jpg ');
Var dogandcat = document. getElementsByName ('domainandcat'); // obtain all the single-choice buttons with name = dogandcat
For (var I = 0; I <dogandcat. length; I ++ ){
If (dogandcat [I]. checked = true ){
Var value = dogandcat [I]. getAttribute ('value ');
Switch (value ){
Case '2 ':
Document. getElementById ('img1'). setAttribute ('src', 'images/2.jpg ');
Break;
Case '3 ':
Document. getElementById ('img1'). setAttribute ('src', 'images/3.jpg ');
Break;
Case '4 ':
Document. getElementById ('img1'). setAttribute ('src', 'images/4.jpg ');
Break;
Case '6 ':
Document. getElementById ('img1'). setAttribute ('src', 'images/6.jpg ');
Break;
}
}
}
}
</Script>

</Head>
<Body>

<Br/>
<Input type = "button" value = "change image" onclick = "UpdateImg ();"/>
<Br/>
<Input id = "Radio1" name = "dogandcat" type = "radio" value = "2" onclick = "UpdateImg ();"/> sad puppy
<Input id = "Radio2" name = "dogandcat" type = "radio" value = "3" onclick = "UpdateImg ();"/> selling cute puppies
<Input id = "Radio3" name = "dogandcat" type = "radio" value = "4" onclick = "UpdateImg ();"/> angry puppies
<Input id = "Radio4" name = "dogandcat" type = "radio" value = "6" onclick = "UpdateImg ();"/> cute kitten
</Body>

The following is the interface for running the program: different button images are different

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.