UNPKG

italia2024

Version:

Italia 2024 assets

36 lines (31 loc) 1.52 kB
//_unlock-checkkey.js(すべてチェックでロック開錠) (function () { //チェックボックスの状態を監視する関数 let funcUnLockP03A = function () { let arrCKeyP03As = Array.prototype.slice.call(document.querySelectorAll(".checkkey")); let arrLckDP03As = Array.prototype.slice.call(document.querySelectorAll(".is-locked")); //Arr.NodeList //すべてのチェックボックスがチェックされているか確認 const allChecked = arrCKeyP03As.every(arrCKeyP03A => arrCKeyP03A.checked); //各.is-locked要素に対してクラスの変更を行う let lngtP03A = arrLckDP03As.length; for (let n = 0; n < lngtP03A; n++) { //action if (allChecked) { //すべてチェックされている場合は、.is-lockedを削除して.is-unlockedを追加 arrLckDP03As[n].classList.remove('is-locked'); arrLckDP03As[n].classList.add('is-unlocked'); } else { //すべてチェックされていない場合は、.is-lockedを追加して.is-unlockedを削除 arrLckDP03As[n].classList.add('is-locked'); arrLckDP03As[n].classList.remove('is-unlocked'); } }; ///for }; //チェックボックスの変更を監視 let arrCKeyP03As = Array.prototype.slice.call(document.querySelectorAll(".checkkey")); arrCKeyP03As.forEach(arrCKeyP03A => { arrCKeyP03A.addEventListener('change', funcUnLockP03A); }); //初期ロード時にもチェック状態を確認 funcUnLockP03A(); })(); ///function();