JQuery操作radio表单元素
代码
<!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=utf-8" />
<title>无标题文档</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
//默认选中第一个radio按钮
//第一种方式:
//$(":radio").get(0).checked=true;
//第二种方式:
$($("input[name='Evaluation']").get(0)).attr("checked", true);
//单击事件,得到选中的radio按钮的值
$('#submit').bind("click",function(){
alert($("input[name='Evaluation']:checked").val());
});
});
</script>
</head>
<body>
<input name="Evaluation" type="radio" value="11" />11
<br />
<input name="Evaluation" type="radio" value="22" />22
<br />
<input name="Evaluation" type="radio"value="33" />33
<input type="button" id="submit" value="提交" />
<br />
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
//默认选中第一个radio按钮
//第一种方式:
//$(":radio").get(0).checked=true;
//第二种方式:
$($("input[name='Evaluation']").get(0)).attr("checked", true);
//单击事件,得到选中的radio按钮的值
$('#submit').bind("click",function(){
alert($("input[name='Evaluation']:checked").val());
});
});
</script>
</head>
<body>
<input name="Evaluation" type="radio" value="11" />11
<br />
<input name="Evaluation" type="radio" value="22" />22
<br />
<input name="Evaluation" type="radio"value="33" />33
<input type="button" id="submit" value="提交" />
<br />
</body>
</html>