프로젝트에서 연구하는 과제입니다.
철판의 재질이 나오면, 그 재질을 요약해서 버튼을 만들고 그 버튼이 클릭되면 해당 재질만 체크되고 해제되는 로직...
이틀째 연구중인데 그리 쉽지 않네요.
첫번째 코드 완성
var value = $(this).text();
var rows = document.querySelectorAll('table tr');
var count = 0;
rows.forEach(function(row) {
var specElement = row.querySelector('.spec');
var checkbox = row.querySelector('input[name="checkbox[]"]');
if (specElement && checkbox) {
var specText = specElement.textContent.trim();
var checkboxValue = checkbox.previousElementSibling.textContent.trim();
if (specText === value && checkboxValue === '레이져') {
console.log('선택했을 때 specText: ' + specText);
console.log('value: ' + value);
console.log('checkboxValue: ' + checkboxValue);
console.log(checkbox);
checkbox.checked = !checkbox.checked;
count++;
}
}
});
console.log('checkbox 반복 회수: ' + count);
30회 이상 코드를 수정해서 만든건데 만족도 높습니다.
실제 제작중인 화면, 위의 재질을 클릭하면 해당 재질의 레이져가 체크되는 상태...
코드 기록을 남겨둡니다.
반응형
'IT tech Coding > javascript' 카테고리의 다른 글
[JS] 순회하면서 테이블의 요소 찾기 (0) | 2023.08.10 |
---|---|
테이블에 td요소중에 1행과 1열은 제외하고 넣어주는 코드는? 만약에 matchlist0부터 10까지 있다면 다 적용하려면? (0) | 2023.08.06 |
자바스크립트+PHP 화면의 선택사항 간단히 쿠키저장 후 불러오기 (0) | 2023.07.05 |
[javascript] 인터벌을 줘서 계속 자료를 불러오고 싶을때 만든 코드 (0) | 2023.07.03 |
[javascript] table에서 두줄로 되어 있을때 합쳐진 셀에서 나눠진 아랫셀의 합계를 내고 싶을때 알아야 할 코드 (1) | 2023.07.02 |