登录界面获取用户名密码,在第二个页面读出该用户名,然后显示。

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/longyanyang_yan/article/details/50768042
</pre><pre name="code" class="html">1.用户输入用户名、密码:
 <form id="login_form">
                 <div class="parentCls">
                      <input id="phone_number" class="inputElem" type="text" name = "user_name" placeholder="请输入用户名"/>
            
                      <input id="veri_code" type="password" name="user_password" placeholder="请输入密码"/>
                  </div>
                      <input id="login_register" type="submit" value="注册" οnclick="openWin('user_register')"/>  <!--注册--> 
                           
                      <input id="login_submit" type="submit" value="登录" οnclick="open_login_page()"/>
 
            </form>

2.在1中点击登录则onclick  open_login_page()函数:

open_login_page()中获取name,password,调用send_login_info(),send_login_info()判断是否登录成功,登录成功则open_logged()

<span>	</span>function open_login_page() {	
  		
		var name=document.getElementById("phone_number").value;
		var password=document.getElementById("veri_code").value;
	
      	send_login_info(name,password);         
	 } 
	 
	 
   	function send_login_info(name, password) {	
  		//alert("s");
	  		
  		if (name == "" || password == ""){
			alert("账号名和密码不能为空");
    	}else{ 
	  		
	  		api.ajax({
	  		 
			    url: HOST_URL+ '/museum/user_login.php?user_name='+name+'&user_password='+password,
			    method: 'post',
			    timeout: 30,
			    dataType: 'json',
			    returnAll:false
			
			},function(ret,err){
			    if (ret) {
			    	if(ret.state=="0"){
			    		alert("登陆成功!");
			    		open_logged(name, password);
			    	}else if(ret.state=="2"){
			    		alert("账号不存在");
			    		//return;
			    	}else if(ret.state=="3"){
			    		alert("密码错误");
			    		//return;
			    		}
			       // var urlJson = JSON.stringify(ret);
			       // api.alert({msg: urlJson});
			        
			    }else {
			        alert({
			            msg:('错误码:'+err.code+';错误信息:'+err.msg+'网络状态码:'+err.statusCode)
			        });
			    }
			});
		//	alert(name+","+password);
			alert("消息同步中……");
		    
			}
	 	}
	 
	  function open_logged(name, password) {<span>	</span>
<span>	</span>  //alert("sss");
<span>	</span>  <span>	</span>//alert(name +';' + password);
<span>	</span>  <span>	</span>api.openWin({
<span>	</span>      name:'user_logged',
<span>	</span>      url:'user_logged.html',
<span>	</span>      opaque:true,
<span>	</span>      vScrollBarEnabled:false,
<span>	</span>      hScrollBarEnabled:false,
<span>	</span>      animation:{
<span>	</span>          type:"push",
<span>	</span>          subType:"from_right",
<span>	</span>          duration:300
<span>	</span>      },
<span>	</span>      pageParam: {account_name:name,account_pwd:password}
<span>	</span>  });
<span>	</span>}
    </script>
    


3、在open_loggen()中,有pageParam函数,就可以把account_name,account_pwd传到下一个页面:

4、在user_logged.html中:

 <div class="user-action">
                    <label class="name" id="nname"></label>
                    



 <script type="text/javascript">
    	apiready = function(){
    		var pageParam = api.pageParam;
    		var name = pageParam.account_name;
    		var password = pageParam.account_pwd;
//    		alert(name);
  //  		alert(password);
    		var nname = document.getElementById("nname");
    		nname.innerText = name;    //lable赋值不能用nname.value,只能用innerText
    	}

用label就可以了。

展开阅读全文

没有更多推荐了,返回首页