<!DOCTYPE html>
<html>
<body>
<script type="text/javascript">
function select_patten(value)
{
// varvalue=document.getElementsByName(text).value;
// alert(‘hello‘);
alert(value);
}
</script>
//以下这种方式只能获得单个单选按钮的value,并不能判断出来是哪个单选按钮被选中
<script type="text/javascript">
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 onclick=select_patten(this.value)>文本</td>
<td></td><td></td>
<td><input type=radio name=‘text‘ id=‘file‘ value=‘file‘ onclick=select_patten(this.value)>文件</td>
</tr>
<tr>
<td><input type=radio id=‘apple‘ name=‘fruit‘ value=‘apple‘ checked=checked onclick=get_value_byid()>苹果</td>
<td></td><td></td>
<td><input type=radio id=‘banana‘ name=‘fruit‘ value=‘banana‘ onclick=get_value_byid()>香蕉</td>
</tr>
<tr>
<td><input type=radio id=‘car‘ name=‘vehicle‘ value=‘car‘ checked=checked onclick=get_value_byname()>汽车</td>
<td></td><td></td>
<td><input type=radio id=‘bycicle‘name=‘vehicle‘ value=‘bycicle‘ onclick=get_value_byname()>自行车</td>
</tr>
</table>
</body>
</html>