<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title> new document </title> <meta name="generator" content="editplus" /> <meta name="author" content="" /> <meta name="keywords" content="" /> <meta name="description" content="" /> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> </head> <body> <script type="text/javascript"> <!-- function isNRIC() { var nricNo = "S"+ RndNum(7); var ic = nricNo.toUpperCase(); var d = ic.split(""); var checker = ""; switch (d[0]) { case "S": checker = "ABCDEFGHIZJ"; break; case "T": checker = "HIZJABCDEFG"; break; case "F": checker = "KLMNPQRTUWX"; break; case "G": checker = "TUWXKLMNPQR"; break; default: return false; } var ChkDigit = checker.split(""); var sum = 2 * d[1] + 7 * d[2] + 6 * d[3] + 5 * d[4] + 4 * d[5] + 3 * d[6] + 2 * d[7]; var checksum = 11 - (sum % 11) - 1; checksum = checksum == -1 ? 10 : checksum; var LastDigit = ChkDigit[checksum]; $("#nric").val(nricNo + LastDigit); } function RndNum(n){ var rnd=""; for(var i=0;i<n;i++) rnd+=Math.floor(Math.random()*10); return rnd; } //--> </script> <input type="text" id="nric" value="" /> <input type="button" value="get nric" onclick="isNRIC()" /> </body> </html>
记录一下