分类目录归档:前端

js监听radiobox

纯js方式

<html>
 <head>
  <script type ="text/JavaScript">
  function judgeGender()
  {
   var obj =document.getElementsByName("gender");
   for(var i =0;i < obj.length;i++)
   {
    if(obj[i].checked)
    {
      alert('你选择了:'+ obj[i].value);
    }
   }
  }
  </script>
 </head>
 <body>
  <input type ="radio" name = "gender" value = "男" onchange ="judgeGender();">男 <br>
  <input type ="radio" name = "gender" value = "女" onchange ="judgeGender();">女 <br>
 </body>
</html>

jq方式

//later