我有一个登录页面,需要用户名和密码才能转到主页。
所以我有两个字段用于用户名,另一个用于密码。输入用户名和密码后,您必须按回车键(从键盘),因为我已隐藏提交按钮。
我已经在mozilla firefox和Opera浏览器中进行了测试,它的工作原理很完美,但在google chrome中却无法正常工作。请告诉我该怎么做。
<%@ page import="java.sql.*" %>
<%@ page import="DB.*" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Spanwave</title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>DiaEmr</title>
<link href="style.css" rel="stylesheet" type="text/css" media="screen" />
<script type="text/javascript">
function ccheck()
{
uid=document.getElementByName('uid').value;
cpass=document.getElementByName('cpass').value;
if(uid=="" || uid==null)
{
alert("Plz. Enter Your User ID");
document.f1.uid.focus();
return false;
}
if(cpass=="" || cpass==null)
{
alert("Plz. Enter Your Password");
document.f1.cpass.focus();
return false;
}
return true;
}
</script>
</head>
<body>
<%
if(session.getAttribute("login")==null)
{
%>
<div id="menu-wrapper"> <<center><h2>Diabetes Surgery-Data Registry</h2> </center>
<div id="menu">
<ul>
</ul>
</div>
<!-- end #menu -->
</div>
<div id="banner"><a href="#"><img src="images/img01.jpg" width="1000" height="500" alt="rotating image" id="rotator"></a></div>
<div id="header-wrapper">
<div id="header">
<div id="logo">
<h1><a href="#">Dia<span>EMR</span></a></h1>
<p>Website design by <a href="http://www.spanwave.com">Spanwave</a></p>
</div>
</div>
</div>
<div id="wrapper">
<!-- end #header -->
<div id="page">
<div id="page-bgtop">
<div id="page-bgbtm">
<div id="sidebar">
<ul>
<li>
<h2>Portal Login</h2>
<div >
<form id="f1" name="f1" method="post" action="authentication.jsp" onsubmit="return ccheck()">
User Name<input type="text" name="uid" id="search-username" value="" />
Password<input type="password" name="cpass" id="search-password" value="" />
<input type="submit" id="search-submit" value="" /><br><br>New User<a href="UserRegistration.jsp">Register </a>
</form>
</div>
</ul>
</div>
<!-- end #sidebar -->
<div id="content">
<div class="post">
<h2 class="title">Welcome to DiaEmr </h2>
<div style="clear: both;"> </div>
<div class="entry">
<p>welcome to all the <strong>"Workshop on Ileal Interposition".</strong>,
<b>Brazil</b> to inaugurate & launch this very important Data Registry<br>
Key features of the solution-<br>
-Electronics Medical Records<br>
-Data Analysis<br>
-Easy Appointment Scheduling<br>
-Patient Reminder<br>
-Anytime,Anywhere Access<br>
-Highly Secured Data<br>
-Rich User Interface
</div>
</div>
</div>
</div>
</div>
<div style="clear: both;"> </div>
</div>
<!-- end #content -->
<div style="clear: both;"> </div>
</div>
</div>
</div>
<!-- end #page -->
</div>
<div id="footer">
<p>© 2013 Spanwave.com | Design by <a href="http://www.spanwave.com">Spanwave</a>.</p>
</div>
<!-- end #footer -->
<script type="text/javascript">
(function() {
var rotator = document.getElementById('rotator');
var imageDir = 'images/';
var delayInSeconds = 5;
// list image names
var images = ['img02.jpg', 'img03.jpg', 'img04.jpg', 'img01.jpg'];
// don't change below this line
var num = 0;
var changeImage = function() {
var len = images.length;
rotator.src = imageDir + images[num++];
if (num == len) {
num = 0;
}
};
setInterval(changeImage, delayInSeconds * 1000);
})();
</script>
<%}else{response.sendRedirect("frameSet.jsp");}%>
</body>
</html>
答案 0 :(得分:0)
浏览器可能没有将Enter键击为“提交”。我遇到了类似的问题并使用了一个eventhandler来监听所需的击键并通过JavaScript进行提交。像这样:
function doAfterEvent(evt) {
evt = (evt) ? evt : ((event) ? event : null);
if (evt.keyCode == 13) {
document.logein.submit();
}
return;
}
不是最好的代码,但可能会让你朝着正确的方向前进。
答案 1 :(得分:0)
删除您编写两次的脚本
<script type="text/javascript">
$(function() { //HERE
var rotator = document.getElementById('rotator');
var imageDir = 'images/';
var delayInSeconds = 5;
// list image names
var images = ['img02.jpg', 'img03.jpg', 'img04.jpg', 'img01.jpg'];
// don't change below this line
var num = 0;
var changeImage = function() {
var len = images.length;
rotator.src = imageDir + images[num++];
if (num == len) {
num = 0;
}
};
setInterval(changeImage, delayInSeconds * 1000);
}); //HERE
</script>
并为
提供不同的IDUser Name<input type="text" name="uid" id="search-username" value="" />
Password<input type="password" name="cpass" id="search-password" value="" />
和on function check()尝试像这样编辑
function ccheck()
{
uid=document.getElementByName('uid').value;
cpass=document.getElementByName('cpass').value;