JS自动填写表单,文本框清除焦点?

时间:2017-08-24 01:39:19

标签: javascript html

我正在尝试通过javascript自动填写表单。现在,我遇到的问题是,当我填写完这些文本框后,我会把所有那些文本框填满,清空文本框?有人可以告诉我为什么这样做以及我如何通过它。

JS:

window.setTimeout(function () { 
    document.getElementsByClassName("_ph6vk _623pz _o716c")[0].focus(); 
}, 1000); 

window.setTimeout(function () { 
    document.getElementsByClassName("_ph6vk _623pz _o716c")[0].value = "some value 0";
}, 2000); 

window.setTimeout(function () { 
    document.getElementsByClassName("_ph6vk _623pz _o716c")[1].focus(); 
}, 3000); 

window.setTimeout(function () { 
    document.getElementsByClassName("_ph6vk _623pz _o716c")[1].value = "some value 2";
}, 4000); 

HTML:

<form class="_asaim">
    <div class="_fhskl">
        <div class="_j5suk"></div>
        <div class="_hxmdu">
            or
        </div>
        <div class="_j5suk"></div>
    </div>
    <div class="_agqzm">
        <div class="_sjplo _8ki4j">
            <input aria-describedby="" aria-label="Mobile Number or Email" aria-required="true" class="_ph6vk _623pz _o716c" name="emailOrPhone" placeholder="Mobile Number or Email" type="text" value="d">
            <div class="_gaby6">
                <span class="coreSpriteInputError _eyp7r"></span>
            </div>
        </div>
    </div>
    <div class="_agqzm">
        <div class="_sjplo _8ki4j">
            <input aria-describedby="" aria-label="Full Name" aria-required="false" class="_ph6vk _623pz _o716c" name="fullName" placeholder="Full Name" type="text" value="d">
            <div class="_gaby6">
                <span class="coreSpriteInputAccepted _eyp7r"></span>
            </div>
        </div>
    </div>
    <div class="_agqzm">
        <div class="_sjplo _8ki4j">
            <input aria-describedby="" aria-label="Username" aria-required="true" class="_ph6vk _623pz _o716c" maxlength="30" name="username" placeholder="Username" type="text" value="d">
            <div class="_gaby6">
                <span class="coreSpriteInputError _eyp7r"></span>
            </div>
        </div>
    </div>
    <div class="_agqzm">
        <div class="_sjplo _8ki4j">
            <input aria-describedby="" aria-label="Password" aria-required="true" class="_ph6vk _623pz _o716c" name="password" placeholder="Password" type="password" value="d">
            <div class="_gaby6">
                <span class="coreSpriteInputError _eyp7r"></span>
            </div>
        </div>
    </div>
    <div>
        <span class="_9mno0 _ov9ai"><button class="_qv64e _gexxb _4tgw8 _njrw0"><span class="_9mno0 _ov9ai">Sign up</span></button></span>
    </div>
    <p class="_fd2m9"><!-- react-text: 144 -->By signing up, you agree to our <!-- /react-text --><a class="_nzfks" href="/legal/terms/" target="_blank">Terms</a><!-- react-text: 146 --> &amp; <!-- /react-text --><a class="_nzfks" href="/legal/privacy/" target="_blank">Privacy Policy</a><!-- react-text: 148 -->.<!-- /react-text --></p>
</form>

1 个答案:

答案 0 :(得分:0)

在没有看到所有代码的情况下很难判断,但是你发布的代码只是在经过一段时间后设置输入值(你在setTimeout函数中指定的毫秒数),所以我怀疑你正在做一些导致这些超时函数被调用的东西,它会覆盖输入。我猜测输入清除的原因可能是值,例如“某些值0”实际上并不作为相关输入的“值”存在,因此输入只是被清除,因为无法找到指定的值?除非你发布完整的代码,否则我无法完全确定。