jquery radiobox

■ jquery radiobox

<!DOCTYPE html>
<html lang="ko_KR">

<head>
<title>radio test</title>
<script type="text/javascript" src="./jquery-1.12.2.min.js"></script>
<script type="text/javascript">

$(document).ready(function() {
	$("input[type=radio][name=status]").change(function(){
		$("#log").prepend("selected label, value : " + $(this).next().text() +", "+ $(this).val() + "<br/>");
	});

	// radio box의 값이 'v3'인 라디오 버튼을 체크.
	var chkVal = 'v3';
	$("input:radio[name=status]:input[value='"+chkVal+"']").attr("checked",true);
	});
</script>

</head>

<body>

<div style="width:50px">
	<input type="radio" id="r1" name="status" value="v1">
	<label for="r1">R1</label>
	<input type="radio" id="r2" name="status" value="v2">
	<label for="r2">R2</label>
	<input type="radio" id="r3" name="status" value="v3">
	<label for="r3">R3</label>
	<input type="radio" id="r4" name="status" value="v4">
	<label for="r4">R4</label>
	<input type="radio" id="r5" name="status" value="v5">
	<label for="r5">R5</label>
</div>
<div id="log"/>
</body>

</html>

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다