html界面
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
#codeInput{
height: 29px;
}
#button{
height: 35px;
}
#code{
height: 33px;
display: inline-block;
border: 2px solid black;
width: 80px;
text-align: center;
line-height: 33px;
}
#correct{
color: green;
}
#errorTips{
color: red;
}
.overtime{
font-size: 12px;
color: black;
opacity: 0.6;
}
</style>
</head>
<body>
<div >
<div class="yzm">
<input id="codeInput" type="text">
<span id="code">点击获取</span>
<button id="button">验证</button>
<span id="correct"></span>
<span id="errorTips"></span>
</div>
<div class="overtime">
你有<span id="msg1">0</span>分钟没有动作了!<br>
再过<span id="msg2">0</span>分钟,页面将自动跳转首页!<br>
快动下鼠标!
</div>
</div>
<script src="js/jquery.js"></script>
<script src="js/yanzhenma.js"></script>
<script src="js/overtime.js"></script>
</body>
</html>
长时间未操作自动返回界面
var timeout =2000;
var occurtime=new Date().getTime() ;
document.onmousemove=function(){
occurtime=new Date().getTime() ;
}
function goUrl(){
var a = parseInt(new Date().getTime() - occurtime) ;
$("#msg1").html((a/2000).toFixed(1));
$("#msg2").html(((timeout - a)/2000).toFixed(1))
if(a>timeout){
window.location.href="index.html";
alert("您已经长时间未操作,已登出系统,请重新登录");
}
}
window.setInterval("goUrl()",100);
验证码代码块
$('#code').unbind('click').bind('click',function () {
changeImg();
}) ;
function changeImg(){
var arrays=new Array('1','2','3','4','5','6','7','8','9','0','!','@','#','$','%','^','&','*','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
code ='';
for(var i = 0; i<4; i++){undefined
var r = parseInt(Math.random()*arrays.length);
code += arrays[r];
}
$('#code').html(code);
}
$('#button').unbind('click').bind('click',function () {
yanzhen();
});
function yanzhen() {
var code=$('#code').text();
var codeinput=$('#codeInput').val();
var correct;
var error;
if (code==codeinput){
correct='验证码一致';
$('#correct').html(correct);
$('#correct').show();
$('#errorTips').hide()
}else{
error='验证码输入错误,请重新输入';
$("#errorTips").html(error);
$('#correct').hide();
$("#errorTips").show();
}
}