I'm

Developer, Designer, Photographer

GET IN TOUCH

  • Buk-gu, Busan, Republic of Korea
  • ungdoli0916@naver.com
  • Kakao ID : Ungdoli
Your message has been sent. Thank you!
(즐거웅코드) 제이쿼리 checkbox 선택된(체크된) 객체 값(value) 모두 가져오기 (name으로 확인)

· 즐거'웅' 코드 (Source)/HTML & CSS & JAVASCRIPT
2020. 3. 18. 21:57

반응형
jQuery
1
2
3
4
5
6
7
8
9
10
<script>
    var select_obj = '';
  
    $('input[type="checkbox"]:checked').each(function (index) {
        if (index != 0) {
            select_obj += ', ';
        }
        select_obj += $(this).val();
    });
</script>
예제 소스
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
  
<input type="checkbox" name="fruit" value="apple"/>사과
<input type="checkbox" name="fruit" value="strawberry"/>딸기
<input type="checkbox" name="fruit" value="lemon"/>레몬
<input type="checkbox" name="fruit" value="mango"/>망고
<input type="checkbox" name="fruit" value="melon"/>메론
  
<button onclick="test()">checkbox 선택(체크)된 객체 값(value) 가져오기</button>
  
<script>
    function test() {
        var select_obj = '';
  
        $('input[type="checkbox"]:checked').each(function (index) {
            if (index != 0) {
                select_obj += ', ';
            }
            select_obj += $(this).val();
        });
  
        alert(select_obj);
    }
</script>
구현 예시
반응형