엄지월드

javascript checkbox 값 가져오기 본문

Front

javascript checkbox 값 가져오기

킨글 2023. 1. 10. 10:42

 

 

<input type="checkbox" name="basketList" data-id="111" checked>
<input type="checkbox" name="basketList" data-id="222" checked>
<input type="checkbox" name="basketList" data-id="333">

<script>
    document.querySelector("#updatePwd").onclick = (event) => {
        let query = 'input[name="basketList"]:checked';
        let selectedEls = document.querySelectorAll(query);
        let result = '';
        selectedEls.forEach((el) => {
           result += el.getAttribute("data-id")+",";
        });        
    }
    console.log(result);
</script>

'Front' 카테고리의 다른 글

CK Editor5 글 수정  (0) 2022.12.11
CSS 버튼 색 추가  (0) 2022.11.24
An invalid form control with name='contents' is not focusable.  (0) 2022.08.23
로딩바 만들기  (0) 2022.07.27
table tr 제거  (0) 2022.07.27
Comments