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