自动登录

时间:2016-05-22 07:44:54

标签: javascript jquery html ajax

我试图自动登录用户。这里的JavaScript代码实际上是这样做的,但只有在我删除' login / submit' div(),然后当我包含' div'时停止工作。我无法删除这个' div' div因为那是我的提交按钮。我不知道如何解决这个问题,任何帮助将不胜感激。

HTML;

If Not IsEmpty(Cells(8, y)) Then

JAVASCRIPT;

<body>

<form name="EventConfirmRedirection" class="Form" method="post" action="index.php" id="myForm" data-ajax="false">
  <div class="user_login3"><input style="text-transform:lowercase" type="text" name="username" id="username" placeholder="username"></div> 
  <div class="user_login3"><input type="password" name="password" id="password" placeholder="password"></div>

    <div style="margin-left:5%; width:45%; font-size:5px;">
        <input data-theme="c" type="checkbox" id="rememberMe" name="rememberMe"/>
        <label for="rememberMe"><span style="font-size:12px">remember me</span></label>
    </div>   

    <div style="margin-left:5%; color:#FF0000; font-weight:bold" id="error"></div>



    <div class="login"><input type="submit" value="LOGIN" name="submit" data-theme="e" id="submit"></div>
</form>

</body>

AJAX

$(document).ready(function() {

"use strict";

    if (window.localStorage.checkBoxValidation && window.localStorage.checkBoxValidation !== '') {
        $('#rememberMe').attr('checked', 'checked');
        $('#username').val(window.localStorage.userName);
        $('#password').val(window.localStorage.passWord);
        document.EventConfirmRedirection.submit();
    } else {
        $('#rememberMe').removeAttr('checked');
        $('#username').val('');
        $('#password').val('');
    }

     $('#rememberMe').click(function() {

        if ($('#rememberMe').is(':checked')) {
            // save username and password
            window.localStorage.userName = $('#username').val();
            window.localStorage.passWord = $('#password').val();
            window.localStorage.checkBoxValidation = $('#rememberMe').val();
        } else {
            window.localStorage.userName = '';
            window.localStorage.passWord = '';
            window.localStorage.checkBoxValidation = '';
        }
    });
});

1 个答案:

答案 0 :(得分:1)

&#34;提交不是一个功能&#34;表示您将提交按钮或其他元素命名为提交。将按钮重命名为btnSubmit,您的通话将神奇地工作。任何表单元素名称和id都不应该提交,否则form.submit将引用该元素而不是提交函数。

当您将按钮命名为submit时,您将覆盖表单上的submit()函数。

所以改变这样的div / submit对你有用

<div class="login"><input type="submit" value="LOGIN" name="btnSubmit" data-theme="e" id="btnSubmit"></div>

如果您不想更改按钮名称,那么您可以原生调用提交功能,这看起来有点脏......

document.EventConfirmRedirection.prototype.submit.call(document.EventConfirmRedirection);
//or
document.EventConfirmRedirection.prototype.submit.call($('#myForm')[0]);
相关问题