<html>
<body>
<script type="text/javascript">
function select_patten(value)
{
// varvalue=document.getElementsByName(text).value;
// alert('hello');
alert(value);
}
</script>
//下面这样的方式仅仅能获得单个单选button的value,并不能推断出来是哪个单选button被选中
function get_value_byid()
{
var value1=document.getElementById('apple').value;
var value2=document.getElementById('banana').value;
alert(value1);
alert(value2);
}
</script>
<script type="text/javascript">
function get_value_byname()
{
var obj=document.getElementsByName('vehicle');
var i;
for(i = 0; i < obj.length; i++)
{
if(obj[i].checked)
{
alert(obj[i].value);
}
}
}
</script>
<table>
<tr>
<td><input type=radio name=text id='text' value='text' checked=checked οnclick=select_patten(this.value)>文本</td>
<td></td><td></td>
<td><input type=radio name='text' id='file' value='file' οnclick=select_patten(this.value)>文件</td>
</tr>
<tr>
<td><input type=radio id='apple' name='fruit' value='apple' checked=checked οnclick=get_value_byid()>苹果</td>
<td></td><td></td>
<td><input type=radio id='banana' name='fruit' value='banana' οnclick=get_value_byid()>香蕉</td>
</tr>
<tr>
<td><input type=radio id='car' name='vehicle' value='car' checked=checked οnclick=get_value_byname()>汽车</td>
<td></td><td></td>
<td><input type=radio id='bycicle'name='vehicle' value='bycicle' οnclick=get_value_byname()>自行车</td>
</tr>
</table>
</body>
</html>