程序如下:
<!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 src="jquery-1.2.6.min.js" type="text/javascript"></script>
<script type="text/javascript">
/*方法一:
$(function(){
$("#form1").submit(function(){
if($("#form1 input:checked")){
alert($("#form1 input:checked").val());
}
return false; //不提交
});
});
*/
//方法二,实际开发中用
$(function(){
$("#form1").submit(function(){
if($("input[type=radio]:checked")){
//if($("input[name=items]:checked")){
alert($("input[name=items]:checked").val());
}
return false;
})
})
</script>
</head>
<body>
<form id="form1">
<input type="radio" name="items" id="item1" value="a"/>A
<br/>
<input type="radio" name="items" id="item2" value="b"/>B
<br/>
<input type="radio" name="items" id="item3" value="c"/>C
<br/>
<input type="radio" name="items" id="item4" value="d"/>D
<br/>
<input type="radio" name="items" id="item5" value="e"/>E
<br/>
<input type="radio" name="items" id="item6" value="f"/>F
<br/>
<input type="radio" name="items" id="item7" value="g"/>G
<br/>
<input type="radio" name="items" id="item8" value="h"/>H
<br/>
<input type="submit" id="btn1">
</form>
</body>
</html>
本文来自优快云博客,转载请标明出处:http://blog.youkuaiyun.com/lansky07/archive/2008/11/29/3410764.aspx