JavaScript自动执行表单提交

时间:2019-02-28 13:43:24

标签: javascript html forms

我正在尝试使用普通JavaScript自动登录网页。

这是网页上的表单:

<form id="tbb_logon_form" class="login_form" method="post" action="https://www.btopenzone.com:8443/tbbLogon" name="login_form">
    <fieldset class="username-field">
        <label for="email" id="lbl-email">BT ID</label>
        <input type="text" id="username" name="username" class="required" tabindex="3" value="username" placeholder="This is usually your email address">
    </fieldset>
    <fieldset>
        <label for="password">Password</label>
        <input type="password" id="password" name="password" class="required" value="password" tabindex="4">
    </fieldset>
    <input type="submit" value="Login" id="lgnbtn" tabindex="5" id="loginbtn" onclick="var s=s_gi('btiopenzone'); s.linkTrackVars='eVar19,prop50'; s.eVar19='OZ|Home Hub|Landing Page|Account selected:BT Broadband'; s.prop50='OZ|Home Hub|Landing Page|Account selected:BT Broadband'; s.tl(this,'o','OZ|Home Hub|Landing Page|Account selected:BT Broadband');">
    <input name="xhtmlLogon" type="hidden" value="https://www.btopenzone.com:8443/tbbLogon">
</form>

尝试过的事情是:

document.getElementById("lgnbtn").submit();
document.getElementById("lgnbtn").click();

,但都没有自动单击登录按钮。 请帮助我。

1 个答案:

答案 0 :(得分:1)

您可以使用以下方式提交表单:

document.forms[0].submit();

document.forms["login_form"].submit();