无法在Enter上提交表单

时间:2011-04-20 14:28:38

标签: html

我有以下登录表单:

        <!-- login box -->
        <form action="php/login.php" method="POST" id="signin">
        <span id="oldLoginProblem" style="display: inline-block;" ><h3>Login</h3></span>
                    //appears when error
        <span id="newLoginProblem" style="display: inline-block; color: red; font-weight: bold;"><h3>Invalid Login &#183; <a href='recover'>Forgot Password?</a></h3></span>
        <table id="loginTable">
        <tr><td>Email</td><td><input type="text" id="email" name="email" title="Enter your email"/></td></tr>
        <tr><td>Pass</td><td><input type="password" id="password" name="password" title="Enter your password"/>
    <?php
        if(isset($_SERVER['HTTP_USER_AGENT']))
        {
            $agent = $_SERVER['HTTP_USER_AGENT'];
        }
        if(!(preg_match("/firefox/si", $agent)))
        { 
                            //workaround for a jQuery plugin I'm using
            echo "<input type='text'/>";
        }
    ?>  
        </td></tr>
        </table>
        <input type="button" value="Login" id="loginSub"/>
        <input type="button" value="Sign Up" onClick="document.location.href='register'"/>
        </form>

如果需要,我可以在表单外移动“注册”按钮。我只是在按下Enter时尝试使表单提交。现在,它没有这样的事情。该按钮也不是type = submit,因此可能就是这种情况。

有任何帮助吗?我正在使用type =按钮,因为我正在使用jQuery UI按钮。

修改

这是处理我的登录提交的代码。也许我可以让Enter运行这段代码?

$('#loginSub').live('click', function() {
    $.post("php/login.php", $("#signin").serialize(), function(data) {
        if (data == "Invalid") {
            $('#oldLoginProblem').fadeOut('fast', function() {
                $('#newLoginProblem').fadeOut('fast', function() {
                    $('#newLoginProblem').fadeIn('fast');
                });
            });
        }
        else {
            window.location.replace("home");
        }
    });
});

3 个答案:

答案 0 :(得分:2)

$('#input_text').keyup(function(e) {
    if(e.keyCode == 13) {       
    $("#signin").submit();
    }
});

答案 1 :(得分:1)

 $('#input_text').keyup(function(e) {

    if(e.keyCode == 13) {       
            document.singin.submit();

    }
});

答案 2 :(得分:1)

请看一下这个链接:http://www.cs.tut.fi/~jkorpela/forms/enter.html
当您向下滚动一点时,您会找到问题的答案。

相关问题