当前位置: 代码迷 >> Java Web开发 >> 问下有关问题关于JQUERY的~下
  详细解决方案

问下有关问题关于JQUERY的~下

热度:1886   发布时间:2013-02-25 21:17:41.0
问下问题关于JQUERY的~高手指点下~
因为刚学JQUERY请高手指点下:
我做了个登录页面当输入密码正确之后我想让他带值跳入不同的页面。



Login.jsp
<html>
  <head>
  <base href="<%=basePath%>">
   
  <title>My JSP 'Login.jsp' starting page</title>
   
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">  
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<script type="text/javascript" src="script/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="script/Phide.js"></script>

  </head>
  
  <body>
  <center>
  <font size="6" >登陆页面</font><br>
  <form action="">
  <font color=>密码:<input type="password" id="password" value="" maxlength="5" /></font><br>
  <p><input type="submit" value="确认" id="sub"></p>
  </form>
  </center>
  </body>
</html>
JS中写的:

$(document).ready(function(){
$("#sub").click(function(){
var password = $("#password").val();
if (password == null || password == ""){
alert("请输入密码");
return
}
else if (password == ("kfc")) {
alert("普通用户");
  //比如到这里就让他带NORMAL值,我该怎么写(只是顺便问下,)
}
else if (password == ("gm")) {
alert("管理员");
  }
else if (password != ("gm") || password != ("kfc")) {
alert("密码错误");
return
}
  //如果是上面的值是GM跳入这个页面
window.location.href="OK.jsp"; //但是跳不了
  //如果是KFC就跳入另一个页面
window.location.href="OK2.jsp"; //但是跳不了
});
});


------解决方案--------------------------------------------------------
修改了下不保证能过,但是你看看代码思想。
$(document).ready(function(){
$("#sub").click(function(){
var strInfo="";
var password = $("#password").val();
if (password == null || password == ""){
alert("请输入密码");
return
}
else if (password == ("kfc")) {
alert("普通用户");
strInfo="normal";
//比如到这里就让他带NORMAL值,我该怎么写(只是顺便问下,)
}
else if (password == ("gm")) {
alert("管理员");
strInfo="admin"
}
else if (password != ("gm") || password != ("kfc")) {
alert("密码错误");
return
}else{
//如果是上面的值是GM跳入这个页面
window.location.href="OK.jsp"+strInfo; //但是跳不了
//如果是KFC就跳入另一个页面
window.location.href="OK2.jsp"+strInfo; //但是跳不了
}
});
});
------解决方案--------------------------------------------------------
JScript code
$(function(){            $("#sub").click(function(){                var password = $("#password").val();                if (password == null || password == ""){                    alert("请输入密码");                    return                } else if (password == ("kfc")) {                    alert("普通用户");                     //比如到这里就让他带NORMAL值,我该怎么写(只是顺便问下,)                } else if (password == ("gm")) {                    alert("管理员");                    //window.location.href="index.jsp";                    $('form').attr('action','index.jsp');                    $('form').submit();                  } else if (password != ("gm") || password != ("kfc")) {                    alert("密码错误");                    return                }            });        });
  相关解决方案