日期:2014-05-16 浏览次数:20537 次
<!DOCTYPE HTML> <html> <head> <meta charset="gb2312" /> <title></title> </head> <body> <script> function setpwd(){ var mima = []; for(var i = 0; i < 4; i++){ mima.push( Math.floor(Math.random() * 10) ); } var tmp = mima[0] + mima[2]; if(tmp < 10){ tmp = '0' + tmp; } mima.push(tmp); mima = mima.join(''); return mima; } var test = setpwd(); alert( test ) </script> </body> </html>
------解决方案--------------------
var rd = Math.random();
var mima1 = Math.floor((rd*10));
var mima2 = Math.floor((rd*100)) - mima1*10;
var mima3 = Math.floor((rd*1000)) - mima1*100 - mima2*10;
var mima4 = Math.floor((rd*10000)) - mima1*1000 - mima2*100 - mima3*10;
var mima56=mima1 + mima3;
if (( mima56<10))
{
mima56 = '0' + (mima56);
}
var mima = ''+mima1+mima2+mima3+mima4+mima56;
------解决方案--------------------
<!DOCTYPE HTML> <html> <head> <meta charset="gb2312" /> <title></title> </head> <body> <a href="#" id="test">密码</a> <script> function setpwd(){ var mima = []; for(var i = 0; i < 4; i++){ mima.push( Math.floor(Math.random() * 10) ); } var tmp = mima[0] + mima[2]; if(tmp < 10){ tmp = '0' + tmp; } mima.push(tmp); mima = mima.join(''); return mima; } var test = setpwd(); document.getElementById('test').href = 'test.jsp?pwd='+test; </script> </body> </html>
------解决方案--------------------
<!DOCTYPE HTML> <html> <head> <meta charset="gb2312" /> <title></title> </head> <body> <script> function setpwd(){ var mima = []; for(var i = 0; i < 4; i++){ mima.push( Math.floor(Math.random() * 10) ); } var tmp = mima[0] + mima[2]; if(tmp < 10){ tmp = '0' + tmp; } mima.push(tmp); mima = mima.join(''); return mima; } document.write('<a href="http://www.xxx.jsp?pwd='+setpwd()+'" >click</a>') </script> </body> </html>