当前位置: 首页 > 图文教程 > 网络编程 > Javascript > js获取单选按钮的数据

Javascript
form中限制文本字节数js代码
use jscript with List Proxy Server Information
use jscript List Installed Software
List Installed Software Features
List Information About the Binary Files Used by an Application
List the Codec Files on a Computer
List the UTC Time on a Computer
List Installed Hot Fixes
excel操作之Add Data to a Spreadsheet Cell
Add Formatted Data to a Spreadsheet
Apply an AutoFormat to an Excel Spreadsheet
JavaScript语法着色引擎(demo及打包文件下载)
类之Prototype.js学习
一款JavaScript压缩工具:X2JSCompactor
iis6+javascript Add an Extension File
jscript之Open an Excel Spreadsheet
jscript之Read an Excel Spreadsheet
jscript之List Excel Color Values
去除图像或链接黑眼圈的两种方法总结
Add a Formatted Table to a Word Document

Javascript 中的 js获取单选按钮的数据


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-12   浏览: 183 ::
收藏到网摘: n/a

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

<form method="post" name="form1">
<label><input type="radio" name="radio" value="1-10 岁">1-10 岁</label>
<label><input type="radio" name="radio" value="11 岁">11 岁</label>
<label><input type="radio" name="radio" value="12-120 岁">12-120 岁</label>
<input type="button" onclick="ok()" value="测试选择值">
</form>

下面是js获取数据
复制代码 代码如下:

<script language="javascript" type="text/javascript">
<!--
function ok()
{
var temp=document.getElementsByName("radio");
for (i=0;i<temp.length;i++){
//遍历Radio
if(temp[i].checked)
{alert("你选择了"+temp[i].value);
//获取Radio的值
document.form2.textfield.value="你选择了"+temp[i].value;
//传递给另外一个表单
}
}
}
-->
</script>

还想数据传递给另外一个表单
复制代码 代码如下:
<form method="post" name="form2">
<input type="text" name="textfield">
</form>

参考资料
js:http://www.blueidea.com/tech/web/2006/3567_8.asp
form:http://www.netvtm.com/w3s/html/html-forms.html