随机18位身份证号码
最近的系统测试时很多地方要输入身份证号码,嫌麻烦,写了个随机生成18位身份证号的页面,IE的话点击即可复制.
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 2 <HTML XMLNS:ELEMENT> 3 <html> 4 <head> 5 <title>idcard</title> 6 <meta http-equiv="Content-Type" content="text/html;charset=utf-8"> 7 <style> 8 body{ 9 padding-left:10px; 10 } 11 a{ 12 text-decoration: none; 13 color: black; 14 } 15 .aa:hover{ 16 text-decoration: underline; 17 color:#990000; 18 } 19 #panel{ 20 font-size:18px; 21 font-family:微软雅黑; 22 padding:10px; 23 } 24 </style> 25 </head> 26 <body> 27 <button id="getButton">get idcard</button> 28 <div id="panel"></div> 29 </body> 30 </html> 31 32 33 34 35 <script type="text/javascript"> 36 // /地区编码 37 var city = new Array("110113","120223","130403","130425","130433","130731","131000","131023","131024","131081","140106","140222","140226","140227","140524","140600","140828","140922","140981","141129","141130","150426","150525","150727","152525","210201","210300","210801","211101","220103","220182","220203","220323","220500","220821","222400","230108","230307","230703","230710","230833","231003","231222","231223","231281","232721","232722","320201","320302","320503","320584","320724","320831","320902","320982","321003","321081","321181","321201","330000","330108","330122","330183","330205","330225","330411","330600","330723","340103","340207","340301","340603","340802","341221","341421","341521","341822","350206","350427","350526","350721","360421","360425","360428","370105","370611","370685","370687","370883","370900","370921","371311","371422","371424","410302","410782","411081","411421","420607","420800","420900","430102","430122","430225","430301","430401","430511","430624","430922","431027","431127","431201","440306","440703","440923","441400","441821","441827","441882","445321","450100","450224","450521","450701","450923","450981","451022","451029","451421","451424","460200","500232","500237","510106","510112","510183","510503","510601","510683","510903","511524","511602","511823","513224","513229","513328","520300","520326","522422","522633","522700","530103","530501","530702","532600","532622","533324","542100","542125","542227","542322","542331","542421","542424","542525","542626","610301","610429","610528","610702","610901","610926","620524","620901","621124","621201","621226","623026","632126","632523","632821","652300","652901","653000","653022","653121","653123","653128","653200","654021" 38 ); 39 40 41 var pow = new Array("7","9","10","5","8","4","2","1","6","3","7","9","10","5","8","4","2"); 42 var ex = new Array("1","0","X","9","8","7","6","5","4","3","2"); 43 44 // /年月日 45 function getYMD() { 46 var ymd = ""; 47 var y = parseInt(Math.random() * 99); 48 if(y < 10)y = "0" + y; 49 y = "19" + y; 50 var m = parseInt(Math.random() * 13); 51 if(m < 10)m = "0" + m; 52 if(m == "00")m = "01"; 53 var d = parseInt(Math.random() * 28); 54 if(d < 10) d = "0" + d; 55 if(d == "00") d = "01"; 56 ymd = "" + y + m + d; 57 return ymd; 58 } 59 60 //生成号码 61 function makeId(){ 62 var idcard; 63 idcard = city[parseInt(Math.random() * 189)] 64 + getYMD() 65 + parseInt(Math.random() * 9) // 66 + parseInt(Math.random() * 9) // 67 + parseInt(Math.random() * 9); // 68 69 var sum = 0; 70 for(var i = 0;i < idcard.length;i++){ 71 sum += parseInt(idcard.substring(i,i + 1)) * parseInt(pow[i]); 72 } 73 return "<div style='padding:2px;cursor:pointer;' onclick='doCopy(this)'><a class='aa'>" + idcard + ex[sum % 11] + "</a></div>"; 74 } 75 76 //点击复制 只支持ie 77 function doCopy(id){ 78 var str = id.innerText; 79 if(window.clipboardData){ 80 window.clipboardData.clearData(); 81 window.clipboardData.setData("Text", str); 82 } 83 return true; 84 } 85 // / 86 document.getElementById("getButton").onclick = function() { 87 var str = ""; 88 for(var i = 0;i < 50; i++){ 89 str += makeId(); 90 } 91 document.getElementById("panel").innerHTML = str; 92 }; 93 </script>