对话框dialog登录之后,Jquery实现页面定时跳转

<%@ page language="java" import="java.util.*"  contentType="text/html;charset=UTF-8" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML>
<html>
  <head>
  	<!-- jquery基础 1111-->
	<script  src="<%=path%>/js/jquery-1.7.2.min.js"></script>
	<!-- jquery分页表格 -->
	<script  src="<%=path%>/js/jquery.flexigrid.js"></script>
	<!-- jquery拖拽 -->
	<script  src="<%=path%>/js/jquery.draggable.js"></script>
	<!-- jquery调整大小 -->
	<script  src="<%=path%>/js/jquery.resizable.js"></script>
	<!-- jquery按扭 -->
	<script src="<%=path%>/js/jquery.linkbutton.js"></script>
	<!-- jquery阴影 -->
	<script  src="<%=path%>/js/jquery.shadow.js"></script>
	<!-- jquery对话框窗口 -->
	<script  src="<%=path%>/js/jquery.dialog.js"></script>
	<!-- jquery右键菜单 -->
	<script  src="<%=path%>/js/jquery.contextmenu.js"></script>
	<script  src="<%=path%>/js/jquery.contextmenu.packed.js"></script>
	<!-- jquery下拉列表框 -->
	<script  src="<%=path%>/js/jQuery.FillOptions.js"></script>
	<script  src="<%=path%>/js/jQuery.CascadingSelect.js"></script>
  	<link rel="stylesheet"  href="<%=path%>/css/dialog.css"/>
	<script>
	function open_dialog(){
		$("#register-form").dialog({
		 	hide:true,    //点击关闭是隐藏,如果不加这项,关闭弹窗后再点就会出错.
			href:"dialog_login.jsp",
			width:320,
			height:400,
			autoOpen:false,
			modal:true,
			buttons:{
				注册:function(){
					var params=$("#reg-form").serialize();
					params = decodeURIComponent(params,true);  
					//alert(params);
					if(addConsumerValidate(params)){
						$.ajax({
							type: "POST",
							url: "consumer_addConsumerOfDialog.action",
							data: encodeURI(params),
							dataType:"text",
							success: function(msg){
								if(msg=="success"){
									$("#register-form").dialog({closed:true});
									alert("用户注册成功!");
									$("#message").show();
									jump(5);
								}else{
									alert("用户名已存在,请重新输入!");
									$('#register-form#reg-form').reset();
								}
							},
							error: function(msg){
								alert("msg="+msg);
							}
						});
					}
				},
				取消:function(){
	      			//关闭当前Dialog
	      			$("#register-form").dialog({closed:true});
	     		}
			}
		});
	}
	function addConsumerValidate(param){
		//alert(param);
		var user = param.split("&");
      	var name =user[0].split("=")[1];
      	var pass =  user[1].split("=")[1];
      	var reg=/^[1-9]\d*$|^0$/; 
   		if(pass == "" || pass == null || reg.test(pass) == false){
	    	window.alert("密码不能为空且必须为整数");
	    	return false;
	    }
	    else if(name == "" || name == null)
	    {
			window.alert("帐号不能为空");
	    	return false;
		}
		return true;
      }
       function jump(count) {       
            window.setTimeout(function(){       
                count--;       
                if(count > 0) {
                	document.getElementById('time').innerHTML=count;       
                    //$('#last').attr('innerHTML', count);//有问题,不知道什么原因值不改变,倒计时数字不变       
                    jump(count);       
                } else {       
                    window.location="<%=basePath%>login.html";      
                }       
            }, 1000);       
        }       
        
   </script>
  </head>
 <body>
	<div id="register-form" title="用户注册">
	<input type="button" value="打开注册框" onclick="open_dialog();" />
	</div>
	<div id="message" style="display:none">
	<span id="time">5</span>秒后将跳转到项目首页!
	</div>
 </body>
</html>

 

你可能感兴趣的:(jquery,dialog,定时跳转)