天天看點

如何實作點選回車自動送出(當按鈕為圖檔的時候)

<%@ 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%>" target="_blank" rel="external nofollow" >
        <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()" target="_blank" rel="external nofollow" >看不清,換圖</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>
           

繼續閱讀