45IT.COM- 电脑学习从此开始!
DIY硬件教程攒机经验装机配置
设计Photoshop网页设计特效
系统注册表DOS系统命令其它
存储主板显卡外设键鼠内存
维修显卡CPU内存打印机
WinXPVistaWin7unix/linux
CPU光驱电源/散热显示器其它
修技主板硬盘键鼠显示器光驱
办公ExcelWordPowerPointWPS
编程数据库CSS脚本PHP
网络局域网QQ服务器
软件网络系统图像安全
页面导航: 首页 > 设计学院 > 网页设计 >

如何判断radio中的哪个选项被选中?(七)

电脑软硬件应用网 45IT.COM 时间:2005-12-30 19:13 作者:45IT收集


我们经常会在页面上用到radio形式的选项表单,那么我们如何判断当前哪个radio被选中了呢?首先我们做如下的一个函数,它将返回当前被选中的radio选项的值: 
<script><!--
function get_radio_value (radio_array)

{
        var i;

        for (i = 0; i < radio_array . length; ++ i)  //radio_array.length是radio选项的个数

                if (radio_array [i] . checked)

                        return radio_array [i] . value;
        return null;  //如果一项都没选则返回空值

}
//--></script>

  接着,我们通过以下的表单脚本来调用以上函数:

 <form>
  What is your favorite fruit?<br>
  <input type=radio name=fruit value=apple>apple<br>
  <input type=radio name=fruit value=orange>orange<br>
  <input type=radio name=fruit value=banana>banana<br>
  <input type=radio name=fruit value=other>other

  <input type=text name=echotext>

  <input type=button value=echo onClick="form . echotext . value = get_radio_value (form . fruit);">
  <input type=reset value=clear>
 </form>

  当点击"echo" 按扭时,被选中的radio项的值就会显示在echotext框中。 



欢迎咨询/

顶一下
(0)
0%
踩一下
(3)
100%
------分隔线----------------------------
无法在这个位置找到: baidushare.htm
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
验证码:点击我更换图片
推荐知识