js img display:none 和 img src动态切换实现 动态image radio button
代码片段 精选
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<style>
</style>
</head>
<body>
<script>
function myFun(sId) {
var oImg = document.getElementsByTagName('img');
for (var i = 0; i < oImg.length; i++) {
if (oImg[i].id == sId) {
oImg[i].previousSibling.previousSibling.checked = true;
oImg[i].src = 'pulse_letter_a_o.png';
} else {
oImg[i].src = 'c.png';
}
}
}
</script>
<div class="niutuku">
<input type="radio" value= "niutuku" id= "111" name="aaa" style="display:none"> <img id="aa" src="1.png" οnclick="myFun(this.id)">
<input type="radio" value= "niutuku" id= "222" name="aaa" style="display:none"> <img id="bb" src="b.png" οnclick="myFun(this.id)">
<input type="radio" value= "niutuku" id= "333" name="aaa" style="display:none"> <img id="cc" src="c.png" οnclick="myFun(this.id)">
</div>
</body>
</html>