html:
<input name="abc-001-100" value="A" type="radio">
<input name="abc-001-100" value="B" type="radio">
<input name="abc-001-100" value="C" type="radio">
<input type="button" value="check" onclick="checkradio" />Q:如何点击checkradio后,通过js,取得当前html中checked的radio的值?比如选择了第一个,则取到值A?

解决方案 »

  1.   


      <SCRIPT LANGUAGE="JavaScript">
      <!--
    function checkradio(){
    var o=document.getElementsByName("abc-001-100");
    var v=null;
    for(var i=0;i<o.length;i++){
    if(o[i].checked){
    v=o[i].value;
    break;
    }
    }
    if(v!=null)
    alert('选择值为'+v);
    else
    alert('未选择');

    }
      //-->
      </SCRIPT>
     </HEAD> <BODY>
      <input name="abc-001-100" value="A" type="radio"> 
    <input name="abc-001-100" value="B" type="radio"> 
    <input name="abc-001-100" value="C" type="radio"> 
    <input type="button" value="check" onclick="checkradio()" />  </BODY>
      

  2.   


    <!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 content="text/html; charset=utf-8" http-equiv="Content-Type" />
    <title>无标题 1</title>
    <script type="text/javascript" >
    function checkradio()
    {
    var t=document.getElementsByName("abc-001-100");
    for(var i=0;i<t.length;i++)
    {
    if(t[i].checked)
    {
    alert(t[i].value);
    }
    }
    }
    </script>
    </head><body>
    <input name="abc-001-100" value="A" type="radio"> 
    <input name="abc-001-100" value="B" type="radio"> 
    <input name="abc-001-100" value="C" type="radio"> 
    <input type="button" value="check" onclick="checkradio()" /> </body></html>