如何实现点击回车自动提交(当按钮为图片的时候)

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<%

String path = request.getContextPath();

String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

  <head>

    <base href="<%=basePath%>">

   <script type="text/javascript" src="<c:url value="/resources/js/jquery.js"/>"></script>

   <link type="text/css" rel="stylesheet" href='<c:url value="/resources/css/login.css"></c:url>' />

    <title>登录</title>

   <script type="text/javascript">

 function check(){ 

  

   if(document.getElementById("t1").value==0)

   {   

   alert("用户名不能为空!");

   return;

   }

   else if(document.getElementById("t2").value==0){

     alert("密码不能为空!"); 

     return;

   }else {

     document.forms[0].submit();

   }

 $(function(){         

    $('#kaptchaImage').click(function () {//生成验证码  

     $(this).hide().attr('src', 'common/user/handle?' + Math.floor(Math.random()*100) ).fadeIn();  

     event.cancelBubble=true;  

    });  

});   

  

window.onbeforeunload = function(){  

    //关闭窗口时自动退出  

    if(event.clientX>360&&event.clientY<0||event.altKey){     

        alert(parent.document.location);  

    }  

};  

  

function changeCode() {  

    $('#kaptchaImage').hide().attr('src', 'common/user/handle?' + Math.floor(Math.random()*100) ).fadeIn();  

    event.cancelBubble=true;  

}  

function clickBtn(event) {

if (event.keyCode==13) {

        check();

    }

}

</script>  

</head>  

<body onkeypress="clickBtn(event)">

 

<form action="<c:url value="/common/user/loginCheck"/>" method="post">

<div class="text"></div>

<div class="uName"><input type="text"  id="t1" name="loginName"/></div>

<div class="pwd"><input type="password"  id ="t2" name="password"/></div>

<div class="code1">  <input name="chknumber" type="text" id="kaptcha" maxlength="4" class="chknumber_input" />      </div>

<div class="code2"><a href="javascript:changeCode()">看不清,换图</a> 

</div>

<div class="butLogin" ><img src="<c:url value="/resources/images/but_login.png/" />" width=57px; height=29px; onclick="check();"/>

</div>

</form>

 

</body>

</html>

 

你可能感兴趣的:(JavaScript)