http://www.mkyong.com/jquery/how-to-select-a-radio-button-with-jquery/



<html>
<head>
<title>jQuery select a radio button example</title>
 
<script type="text/javascript" src="jquery-1.3.2.min.js"></script>
 
</head>
 
<body>
 
<h1>jQuery select a radio button example</h1>
 
<script type="text/javascript">
 
  $(document).ready(function(){
 
    $("#isSelect").click(function () {
 
	alert($('input:radio[name=sex]:checked').val());
 
    });
 
    $("#selectMale").click(function () {
 
	$('input:radio[name=sex]:nth(0)').attr('checked',true);
	//$('input:radio[name=sex]')[0].checked = true;
 
    });
 
    $("#selectFemale").click(function () {
 
	$('input:radio[name=sex]:nth(1)').attr('checked',true);
	//$('input:radio[name=sex]')[1].checked = true;
 
    });
 
    $("#selectUnknown").click(function () {
 
	$('input:radio[name=sex]:nth(2)').attr('checked',true);
	//$('input:radio[name=sex]')[2].checked = true;
 
    });
 
    $("#reset").click(function () {
 
	$('input:radio[name=sex]').attr('checked',false);
 
    });
 
  });
</script>
</head><body>
 
<input type="radio" name="sex" value="Male">Male</input>
<input type="radio" name="sex" value="Female">Female</input>
<input type="radio" name="sex" value="Unknown">Unknown</input>
 
<br/>
<br/>
<br/>
 
<input type='button' value='Display Selected' id='isSelect'>
<input type='button' value='Select Male' id='selectMale'>
<input type='button' value='Select Female' id='selectFemale'>
<input type='button' value='Select Unknown' id='selectUnknown'>
<input type='button' value='Reset' id='reset'>
 
</body>
</html>

'HTML & Script' 카테고리의 다른 글

숫자값만 받기  (0) 2012.09.19
RSS 2.0 Specification  (0) 2012.07.12
text-overflow:ellipsis  (0) 2012.06.04
IE 인쇄 페이지 설정 컨트롤  (0) 2012.05.04
[Script]특정부분 div태그로 싸서 출력하기  (0) 2012.04.17

+ Recent posts