Start interface as shown:
Copy Code code as follows:
<title></title>
<script type= "Text/javascript" >
function updateimg () {
document.getElementById (' Img1 '). setattribute (' src ', ' images/2.jpg ');
var dogandcat = document.getelementsbyname (' Dogandcat '); Get all Name=dogandcat radio buttons
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>
<body>
<br/>
<input type= "button" value= "Change Picture" onclick= "updateimg ();"/>
<br/>
<input id= "Radio1" name= "Dogandcat" type= "Radio" value= "2" onclick= "updateimg" (); />, sad little dog.
<input id= "Radio2" name= "Dogandcat" type= "Radio" value= "3" onclick= "updateimg" (); />, the little dog that sells the sprouting
<input id= "Radio3" name= "Dogandcat" type= "Radio" value= "4" onclick= "updateimg" (); />, angry little dog.
<input id= "Radio4" name= "Dogandcat" type= "Radio" value= "6" onclick= "updateimg" (); /> Cute kitten.
</body>
The following is the interface of the program Runtime: Clicking on a different button picture is not the same