js获取单选按钮的值

<!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" />
<title>js获取单选按钮的值</title>
<script language="网页特效">
 function getradio( value )
 {
  alert(value ); 
 }
 
 function ck()
 {
  var itemradio = document.getElementsByName("RadioGroup1");
  var itemvalue = ''; 
  for(i=0;i<itemradio.length;i++)    { 
     if(itemradio[i].checked){   
      itemvalue = itemradio[i].value; 
     }
  }
  if( itemvalue !="" )
  {
   alert( itemvalue );
  }
  else
  {
   alert('还未选择');
  }
 }

</script>
</head>

<body>
<form id="form1" name="form1" method="post" action="">
  <p>
    <label>
      <input type="radio" name="RadioGroup1" value="1" id="RadioGroup1_0" onclick="getradio(this.value);" />
      a</label>
    <br />
    <label>
      <input type="radio" name="RadioGroup1" value="2" id="RadioGroup1_1" onclick="getradio(this.value);" />
      c</label>
    <br />
    <label>
      <input type="radio" name="RadioGroup1" value="3" id="RadioGroup1_2" onclick="getradio(this.value);" />
      b</label>
    <br />
    <input type="button" name="button" id="button" value="提交" onclick="ck();" />
  </p>
</form>

</body>
</html>

时间: 2024-08-01 01:31:12

js获取单选按钮的值的相关文章

js 获取radio的值

其实js 获取radio的值是很简单的,如果是单选按钮组的话就遍历一次就行了,如果是单选的就直接判断.value就行了. <!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/xh

控件-C#在在容器panel获取单选按钮的值

问题描述 C#在在容器panel获取单选按钮的值 在panel容器中有两个RadioButton单选按钮,如何获取选中的值 解决方案 获取单选按钮的值获取单选按钮的值 解决方案二: 直接用RadioButton.Value就可以,不管在不在容器中.

js 获取radio按钮值的实例_javascript技巧

复制代码 代码如下: <!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="

js获取单选按钮的数据_javascript技巧

也许这是个很简单的问题,可是在我学习程序的时候忽略了单选按钮.导致对于他的数据传递方法的空缺.经过嗷嗷的帮助实现了下面关于年龄选择的表单的数据获取,仅仅在IE下测试成功了.先测试一下这个程序效果. 复制代码 代码如下: <form method="post" name="form1">     <label><input type="radio" name="radio" value="

js获取select的值实现代码

一款很简单的利用js来获取select当前选中项的值代码,在select有个特别当前值应该是获取它的options的selectedindex的值,这样我们就可以如ojb.options[obj.selectedindex].value来获取了. <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transition

js获取下拉列表的值和元素个数示例_基础知识

js获取下拉列表框元素的个数 复制代码 代码如下: <!DOCTYPE html><html><head><script>function getLength(){alert(document.getElementById("mySelect").length);//元素个数}</script></head><body> <form><select id="mySelect&

js获取name的值的函数

 代码如下 复制代码 /*  * 获取name的值 (必须有值而且可见)  * ele为要获取值得公共父元素  * r : 返回值json格式  */ $.getNameVal = function(ele) {     ele = !!ele ? ele : $("body");     var r = {};     ele.find("[name]").each(function(i, e) {         if( !!$(this).val() &

js获取 清空textarea值代码

js对textarea值的清空与获取值是非常简单的,我们只要给textarea设置一个页面唯的id再利用js document.getelementbyid(id).value就可以了,下面我们来看一个简单的实例. <input type="button" value="获取textarea值" onclick="get();"> <input type="button" value="清除text

js获取radio的值代码详解

把radio的input放在form中, <form name=theform> <input type=text name=input1 value="test"> <input type=radio name="a[]" value="0" checked>选择1 <input type=radio name="a[]" value="1">选择2 <