-
[JavaScript]프론트앤드/Shopify 2023. 9. 9. 17:48728x90
<script> const selectedNailLength = ''; document.querySelector('.nailBtn:nth-child(1)').addEventListener('click',function(){ selectedNailLength = 'short'; console.log('click short'); }) </script>
오류 메시지에서 "Assignment to constant variable"라는 내용을 볼 수 있습니다. 이 오류는 const로 선언된 변수에 값을 다시 할당하려고 할 때 발생합니다. const로 선언된 변수는 한 번 값이 할당되면 다른 값을 할당할 수 없습니다.
따라서 selectedNailLength 변수를 let으로 선언하거나, 이미 const로 선언했다면 다른 변수로 값을 저장하는 방식으로 수정해야 합니다. 아래는 수정된 코드입니다:
<!-- JavaScript 코드 추가 --> <script> // 문서가 준비되면 실행 document.addEventListener("DOMContentLoaded", function () { // 체크박스 요소를 모두 가져옵니다. var checkboxes = document.querySelectorAll('input[type="checkbox"]'); // 모든 체크박스를 체크 상태로 설정합니다. checkboxes.forEach(function (checkbox) { checkbox.checked = true; }); }); </script>
default 값으로 바로 checkbox가 checked 되어있도록
728x90'프론트앤드 > Shopify' 카테고리의 다른 글
[Shopify] story theme 상품목록에 Add to cart 버튼 추가 (0) 2024.01.08 [javascript] 404.liquid 에서 리디렉션 (0) 2023.09.10 [JSON Template] 404-template Designing (1-3) (0) 2023.08.27 [JSON Template] 404-template schema (1-2) (0) 2023.08.26 [JSON Templates] 404 template (0) 2023.08.26