728x90
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script src = "https://code.jquery.com/jquery-3.5.1.min.js"></script>
</head>
<body>
<!-- radio -->
<ul>
<li><input type = "radio" name = "radio_test" value = "사과" checked>사과</li>
<li><input type = "radio" name = "radio_test" value = "배">배</li>
<li><input type = "radio" name = "radio_test" value = "바나나">바나나</li>
</ul>
<button type="button" id = "chioce">선택</button>
<script type="text/javascript">
$(document).ready(function () {
$("#chioce").click(function () {
//getter
/* var radioval = $("input[name='radio_test']:checked").val();
alert(radioval); */
//setter
//var radioval = $("input[name='radio_test']").val(["바나나"]);
/* alert(radioval); */
//왜오류?
});
});
</script>
<br><br>
<!-- /* checkbox */ -->
<input type="checkbox" id = "ch">그림그리기
<!-- 체크박스는 거의 아이디를 쓴다 -->
<br><br>
<button type="button" id = "btn">쳌크</button>
<script type="text/javascript">
$(function() {
$("#btn").click(function() {
//getter
//let check = $("#ch").is(":checked");
//alert("check:" + check);
//아래와 위와 동일
//let check = $("input:checkbox[id = 'ch']").is(":checked");
//alert("check:" + check);
//setter
$("#ch").prop("checked", true);
//ch 아이드를 가진 checkbox가 체크된다.
//false시 체크가 되지않는다.
});
});
</script>
</body>
</html>
728x90
'HTML' 카테고리의 다른 글
jQuery 요소의 선택 , 선택자 정리 블로그 (0) | 2021.03.08 |
---|---|
38일차//JQuery//답글 달기 창 코드 (0) | 2021.03.08 |
38일차//JQuery// button클릭시(태그 추가) 🧨text 추가방법 3가지(스크립트, 제이쿼리) (0) | 2021.03.08 |
38일차//JQuery// 과제 (요소값 변경, 값 가져오기) (0) | 2021.03.08 |
jquery 자주 쓰는 함수 최종정리( .addClass / .css / .text / .html / .append / .prepend (0) | 2021.03.08 |