JavaScript 무 작위 생 성 인증 코드 및 검증 실현
인증 코드(대소 문자 구분)를 입력 하고 확인 을 클릭 하여 검증 합 니 다.틀 리 면 상자 알림
클릭 하여 잘 보이 지 않 음 다시 랜 덤 으로 인증 코드 생 성
 
 인증번호 입력 오류 시 알림
 
 
<body>
    <div class="v_code">
        <div class="code_show">
            <span class="code" id="checkCode"></span>
            <a href="#" id="linkbt">   ,   </a>
        </div>
        <div class="input_code">
            <label for="inputCode">   :</label>
            <input type="text" id="inputCode">
            <span id="text_show"></span>
        </div>
        <input type="button" id="Button1" value="  ">
    </div>
    <script>
        // 1.     
        // 6   0-9 a-f     6       0-9 a-f    
        //       0、1、2……            0-15 
        // 2.          ,    
        window.onload = function() {
            const randomWord = () => {
                let code = '';
                for (var i = 0; i < 6; i++) {
                    var type = getRandom(1,3);
                    switch(type) {
                        case 1:
                            code += String.fromCharCode(getRandom(48,57)) //   
                            break;
                        case 2:
                            code += String.fromCharCode(getRandom(65,90)); //    
                            break;
                        case 3:
                            code += String.fromCharCode(getRandom(97,122));  //    
                            break;
                    }
                }
                return code;
            }
            function getRandom (min, max) {
                return Math.round(Math.random()*(max-min)+min)
            }
            //       
            const rand = randomWord();
            //console.log(rand);
            var checkCode = document.getElementById('checkCode');
            checkCode.innerText = rand;
        
        //        
            var linkbt = document.getElementById('linkbt');
            linkbt.addEventListener('click', function() {
                checkCode.innerText = randomWord();
            })
        //       
            document.getElementById('Button1').onclick = function() {
                var inputCode = document.querySelector('#inputCode');
                if (inputCode.value != checkCode.innerText) {
                    alert('          ');
                    inputCode.value = '';
                    return false;
                } else {
                    alert('    ');
                }
            }
        }
    </script>
</body>이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
[2022.04.19] 자바스크립트 this - 생성자 함수와 이벤트리스너에서의 this18일에 this에 대해 공부하면서 적었던 일반적인 함수나 객체에서의 this가 아닌 오늘은 이벤트리스너와 생성자 함수 안에서의 this를 살펴보기로 했다. new 키워드를 붙여 함수를 생성자로 사용할 때 this는...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.