<!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>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>随机数验证码</title>
<style type="text/css">
#code{width:100px;font-size:12px;height:24px;line-height:24px;
text-align:center;border:1px solid #000;cursor:pointer;}
</style>
</head>
<body>
<div id="code" title="点击这里刷新验证码" onclick="showcode();"></div>
<script type="text/javascript">
//随机出0~100之间的任意一个值!
//1~48 Math.floor( Math.random()*(x2-x1+1) )+x1 范围x1~x2之间
//Math.floor( Math.random()*(x1+1) ) 范围0~x1之间
//Session会话机制
function showcode(){
var x=Math.floor(Math.random()*(6-4+1))+4;
var codestr="蔡新兵0123456789江西信息应用职业技术学院abcdefghijklmnopqrstuvwxyz";
//document.write(codestr[ ( Math.floor( Math.random()*(codestr.length) ) )]);
var outputstr='';
for (var i=0 ;i<x;i++){
outputstr+=codestr[ ( Math.floor( Math.random()*(codestr.length) ) )];
}
document.getElementById('code').innerHTML=outputstr;
}
showcode();
</script>
</body>
</html>