【问题标题】:how to fill fields of the webpage where autocomplete is off如何填写关闭自动完成功能的网页字段
【发布时间】:2022-01-14 00:00:33
【问题描述】:

我想自动填写 HTML 网页上的注册表单字段。表单有多个输入框。我想定义字段的值,当网页出现时,字段会自动填充。之前,我使用了自动填充扩展。但是,字段的自动完成功能已关闭,HTML 对象没有名称或 ID。而且,他们有相同的班级。因此,字段不会自动填充。如何自动填写网页上的字段? 例如,两个输入对象和一些代码定义如下:

<input autocomplete="off" class="red" placeholder="" type="text">

&lt;input autocomplete="off" class="red" placeholder="" type="text"&gt;

<div class="input-item" max-length="10" placeholder="ID" data-v-6b0449e1=""><label class="label"><i>*</i>ID:</label><input autocomplete="off" class="ltr green" max-length="10" placeholder="" type="text"><p class="errors"><ul></ul></p></div>
<div class="select-item" data-v-6b0449e1=""><label class="label"><i>*</i>Sex:</label><select><option hidden="" disabled="" value="">Select</option><option value="false">male</option><option value="true">female</option></select><p class="errors"><ul></ul></p></div>

【问题讨论】:

    标签: html autocomplete autofill


    【解决方案1】:

    如果您希望在页面加载时填写字段,可以使用 JavaScript:

    HTML

    <form class="my-form">
      <input type="text" id="input1" />
      <input type="text" id="input2" />
      <input type="text" id="input3" />
    </form>
    

    JavaScript

    window.onload = function() {
      document.getElementById("input1").value = "This is the first input";
      document.getElementById("input2").value = "This is the second input";
      document.getElementById("input3").value = "This is the third input";
    }
    

    所有这些只是在页面加载时 (window.onload) 将每个指定的 input 字段的值替换为您设置的任何值。

    【讨论】:

    • 我想自动填写 HTML 网页上的注册表单字段。表单有多个输入框。我想定义字段的值,当网页出现时,字段会自动填充。之前,我使用了自动填充扩展。但是,字段的自动完成功能已关闭,HTML 对象没有名称或 ID。而且,他们有相同的班级。因此,字段不会自动填充。如何自动填写网页上的字段?例如,两个输入对象定义如下:&lt;input autocomplete="off" class="red" type="text"&gt;
    • input 元素添加数据的最佳方式是给它一个id,然后在JavaScript (document.getElementById()) 中使用id 给它value。我想不出别的办法。并在 window.onload = function() 函数中执行此操作,因为此处的所有代码在页面加载后立即运行,使其对用户显示为自动填充。
    猜你喜欢
    • 2017-09-12
    • 1970-01-01
    • 2021-10-18
    • 1970-01-01
    • 1970-01-01
    • 2023-02-10
    • 2011-10-23
    • 2013-09-11
    • 1970-01-01
    相关资源
    最近更新 更多