欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

image radio button 带图片的单选按钮

程序员文章站 2022-03-02 11:47:24
...
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" onclick="myFun(this.id)"> 
 <input type="radio" value= "niutuku" id= "222" name="aaa" style="display:none"> <img id="bb" src="b.png" onclick="myFun(this.id)"> 
 <input type="radio" value= "niutuku" id= "333" name="aaa" style="display:none"> <img id="cc" src="c.png" onclick="myFun(this.id)">
</div>
</body>
</html>