input 回车提交

<script type="text/javascript">
    $(document).ready(function() {
        $("#btnLogin").click(function() {
            submitLoginForm();
        });
    });
    function submitLoginForm(event){
        if(event.keyCode==13) {
            var pass = true;
            if ($.trim($("#nickname").val()) == "") {
                $("#nickname_tip").show();
                pass = false;
            } else {
                $("#nickname_tip").hide();
            }
            if ($.trim($("#password").val()) == "") {
                $("#password_tip").show();
                pass = false;
            } else {
                $("#password_tip").hide();
            }
            if ($.trim($("#verify").val()) == "") {
                $("#verify_tip").show();
                pass = false;
            } else {
                $("#verify_tip").hide();
            }
            if (pass) {
                $("#loginForm").submit();
            }
        } 
    }
</script>


<form id="loginForm" name="loginForm" action="__URL__/checkLogin" method="post" style=" height: auto;" >  
    <p>
        <label>用户名:</label>
        <input type="text" name="nickname" id="nickname" onkeydown="submitLoginForm(event)" />
        <span class="tip" id="nickname_tip">请填写用户名</span>
    </p>
    <p>
        <label>密 码:</label>
        <input type="text" name="password" id="password" onkeydown="submitLoginForm(event)"/>
        <span class="tip" id="password_tip">请填写密码</span>
    </p>
    <p>
        <label>验证码:</label>
        <input type="text" name="verify" size="4" autocomplete="off" id="verify" onkeydown="submitLoginForm(event)"/>
        <img src="__URL__/verify/" />
        <span class="tip" id="verify_tip">请填写验证码</span>
    </p>
    <p>
        <input type="button" value="登 录" class="btnLogin" id="btnLogin" />
    </p>
</form>


你可能感兴趣的:(input,回车提交)