代码很简单,如下:<!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>无标题文档</title>
<script language="javascript">
function check()
{
if (document.all.radiobutton[0].checked)
{
alert("1");
}
if (document.all.radiobutton[1].checked)
{
alert("2");
}
return false;
}
</script>
</head><body>
<form id="form1" name="form1" method="post" action="">
<label>
<input type="radio" name="radiobutton" value="radiobutton" />1
</label>
<label>
<input type="radio" name="radiobutton" value="radiobutton" />2
</label>
<p>
<label>
<input type="button" name="button" value="提交" onclick="check();" />
</label>
</p>
</form>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script language="javascript">
function check()
{
if (document.all.radiobutton[0].checked)
{
alert("1");
}
if (document.all.radiobutton[1].checked)
{
alert("2");
}
return false;
}
</script>
</head><body>
<form id="form1" name="form1" method="post" action="">
<label>
<input type="radio" name="radiobutton" value="radiobutton" />1
</label>
<label>
<input type="radio" name="radiobutton" value="radiobutton" />2
</label>
<p>
<label>
<input type="button" name="button" value="提交" onclick="check();" />
</label>
</p>
</form>
</body>
</html>
{
var radiobuttons = document.getElementsByName("radiobutton");if (radiobuttons[0].checked)
{
alert("1");
}
if (radiobuttons[1].checked)
{
alert("2");
}
return false;
}
</script>