随机数

 1 function checkCode(digit){
 2     //自动生成验证码
 3     var result = "";
 4     for(var i = 0;i<parseInt(digit);i++){
 5         result = result+(parseInt(Math.random()*10)).toString();
 6     }
 7     return result;
 8 }
 9 //自定义函数deal(),调用checkCode()函数将转换的字符串显示出来
10 function deal(){
11     result.innerHTML="&nbsp;&nbsp;产生验证码:"+checkCode(form1.digit.value);
12 }
1 <input name = "Submit" type = "button" class="go-wenbenkuang" value = "生成" onclick="deal()">

按如上的方法可生成指定位数的验证码

posted @ 2013-08-26 11:18  最是那一杯红酒  阅读(130)  评论(0编辑  收藏  举报