<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>JS-事件-案例</title>
</head>
<body>
<img id="light" src="img/off.gif"> <br>
<input type="button" value="加边框" onclick="biankuang()">
<input type="button" value="变成50px宽" onclick="off()">
<br> <br>
<input type="radio" name="hobby" checked> 男
<input type="radio" name="hobby"> 女
<br>
<input type="button" value="反选" onclick="reverse()">
</body>
<script>
function biankuang(){
var img = document.getElementById("light");
img.style.border = "1px solid green";
}
function off(){
var img = document.getElementById("light");
img.style.width = "50px";
img.style.height="50px";
}
function reverse(){
var hobbys = document.getElementsByName("hobby");
hobbys[1].checked = true;
}
</script>
</html>
运行效果: