zoukankan      html  css  js  c++  java
  • Javascript 如何得到input type="radio" 的值?

    <script   language="JavaScript">   
      
    <!--   
      
    function   chk(){   
      
    var   obj   =   document.getElementsByName('imgposition');   
      
    for   (i=0;i<obj.length;i++){   
      
    if   (obj[i].checked){   
      alert(obj[i].value);   
      
    return;   
      }
       
      }
       
      alert(
    '你没选');   
      }
       
      
    //-->   
      </script>   
      <form   name=form1>   
      
    <input   type="radio"   name="imgposition"   value="1">   
      
    <input   type="radio"   name="imgposition"   value="2">   
      
    <input   type="radio"   name="imgposition"   value="3">   
      
    </form>   
      <input   type="button"   onclick="chk()">   

    for example:


    <INPUT type=radio name="radio" CHECKED>1-10 years old
    <INPUT type=radio name="radio">11 years old
    <INPUT type=radio name="radio">12-120 years old
    This example uses script to detect which radio button the user selects.

    <SCRIPT>
    function detect()
    {
        
    if (radio[0].checked)
            alert(
    "You're between 1 and 10 years old.")
        
    else if (radio[1].checked)
            alert(
    "You're 11 years old.")
        
    else
            alert(
    "You're between 12 and 120 years old.")
    }

    </SCRIPT>
  • 相关阅读:
    UNIX网络编程 第9章
    UNIX网络编程 第8章 基本UDP套接字编程
    UNIX网络编程 第7章 套接字选项
    UNIX网络编程 第6章 I/O复用:select和poll函数
    UNIX网络编程 第5章 TCP客户/服务器程序示例
    天神下凡
    藏宝图
    黑红树
    杀人游戏[中山市选2011]
    Monotonicity 2[POI2010]
  • 原文地址:https://www.cnblogs.com/goody9807/p/1051484.html
Copyright © 2011-2022 走看看