확인 코드를 생성하고이를 확인하는 코드를 공유하십시오.
<! doctype html public "-// w3c // dtd xhtml 1.0 transitional // en" "http://www.w.w.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"><Html xmlns = "http://www.w3.org/1999/xhtml"> <head> <title> js 검증 코드 생성 </title> <style type = "text/css">. code {background-image : url (code.jpg); font-family : arial; font-style; color; red; pordle : 0; 3px; 문자 스페이스 : 3px; font-weight : bolder;}. 변경되지 않은 {border : 0;} </style> <script language = "javaScript"type = "text/javaScript"> var code; // 검증 코드 함수 정의 createCode () {code = ""; var codelength = 6; // 검증 코드 길이 var checkcode = document.getElementById ( "checkcode"); var selectchar = 새 배열 (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 't', 'u', 'v', 'w', 'x', 'z') (var i = 0; i <codelength; i ++) {var charindex = math.floor (math.random () * 36); 코드 += selectchar [charindex]; } // alert (코드); if (checkCode) {checkCode.className = "Code"; CheckCode.Value = 코드; }} 함수 validate () {var inputCode = document.getElementById ( "input1"). 값; if (inputCode.Length <= 0) {alert ( "확인 코드를 입력하십시오!"); } else if (inputCode! = code) {alert ( "확인 코드 입력 오류!"); createCode (); // verification code} else {alert ( "^-^ ok"); }} < /script> < /head> <body onload = "createCode ()"> <form action = "#"> <입력 유형 = "text"id = "input1" /> <입력 유형 = "text"onclick = "createCode ()"readOnly = "readOnly"id = "checkCode" />> <input id = "onclick ="button1 ";"; type = "button"value = "ok"/> </form> </body> </html>우리 모두 알다시피, JS는 클라이언트 측이므로 클라이언트에 대한 모든 검증을 수행하는 것이 의미가 있습니까? 아니면 서버 안전에서 확인 코드를 생성해야합니까? 검증 코드는 프론트 엔드에 의해 생성됩니까?
검증 코드는 동적이지만 클라이언트가 인식하고 정상적으로 확인하기 전에 올바른 값을 반환해야합니다. 이것은 프로세스 문제입니다. JS 출신이라면 클라이언트에서 확인해야합니다. 이는 기본적으로 같은 것이 없다는 것을 의미합니다! ! ! 서버를 생성하고, 클라이언트를 확인하고, 서버를 확인하고, 정상적으로 탐색하는 것이 가장 좋습니다. 이 과정은 완벽합니다
따라서이 기사는 기술적 인 토론 일 뿐이며 실제 생산 프로젝트에 사용해서는 안됩니다.