퍼블리싱/html css js

[Javascript] 전부 동의했는지 체크하기

임고미 2020. 9. 14. 09:49
728x90
300x250
function agreeAll() {
  var chkbox = document.getElementsByClassName('agree');
  var chk = false;
  for(var i=0 ; i<chkbox.length ; i++) { 
    if(chkbox[i].checked) { 
      chk = true; 
    } else { 
    chk = false; 
    }
  } 
  if(chk) {
    return false; 
  } else { 
    alert("모든 약관에 동의해 주세요.") 
    //체크 안한곳으로 포커스 올리기
    $('#privacy1').focus();
    return false; 
  } 
}
728x90
300x250