触发登录输入密钥

时间:2015-06-11 14:43:30

标签: javascript html login enter

提前道歉,我知道之前已经问过这个问题(我做了搜索)。

我发帖的原因是我需要专门针对我的情况提供帮助,因为我无法用其他例子来解决这个问题。

我试图通过按Enter而不是点击来触发登录,但没有运气(一直在搜索数小时)。

这是我的代码背后:     脚本>

    function loginBtn_Click() {
        doLogin();
    }

    function doLogin() {

        var args = {
            'UserId': document.getElementById('UserId').value,
            'ContactId': document.getElementById('ContactId').value,
            'Password': document.getElementById('Password').value


        };

        var callback = function (data) {
            document.location.href = 'matters.html';
        }

        DoAjaxCall('ws/general.asmx/Login', args, callback);
        }

</script>

这是我的HTML:       

            请输入您的登录详细信息

        <input id="UserId" type="text" placeholder="Username" /><br />
        <input id="ContactId" type="text" placeholder="Contact Reference" /><br />
        <input id="Password" type="password" placeholder="Password" /><br />
        <div id="loginBtn" class="btn" onclick="loginBtn_Click();" onkeypress="DoAjaxCall;">Log in</div>

        <br /><br />

        <p>Error logging in?</p>
        <p>Contact your liason at Buckles Solicitors LLP directly or alternatively call reception on <b>01733 888888</b>.</p>

    </div>

感谢您的帮助。

提前致谢, 拉詹

1 个答案:

答案 0 :(得分:0)

是的,正如Rick S提到的那样,我只是将其更改为输入类型并提交,没有别的,它完美无缺。在css中添加了新代码以引用提交的输入类型,它就像一个魅力!

<div id="main"><br /><br />
        <h2 id="logoutStatus">Please enter your login details</h2>

        <input id="UserId" type="text" placeholder="Username" /><br />
        <input id="ContactId" type="text" placeholder="Contact Reference" /><br />
        <input id="Password" type="password" placeholder="Password" /><br />
        <input type=submit value="Log in" onclick="return loginBtn_Click();">

        <!-- Old log in button, works but no on hitting Enter
        <div id="loginBtn" class="btn" onclick="loginBtn_Click();" onkeypress="return loginBtn_Click();">Log in</div>-->

        <br /><br />

        <p>Error logging in?</p>
        <p>Contact your liason at Buckles Solicitors LLP directly or alternatively call reception on <b>01733 888888</b>.</p>

    </div>

谢谢你们!