繁体   English   中英

如何使输入用户名字段的文本复制到密码字段,使它们相同?

[英]How can I make the text entered into the username field copy to the password field so they are the same?

我知道这很容易,但是我想使密码和用户名一样自动输入,但是我无法实时复制它。

<%=I18n._("Username")%>:</td>
    <td><%data.printTextField(out,UserPerson.FIELD_NAME,null,"text",100,0);%></td>
  </tr>
  <tr style="<%=data.isFacebook ? "display: none" : "" %>">
    <td class="nowrap fieldheader"><span class="note-fieldrequired">*</span> <%=I18n._("Password")%>:</td>
    <td><%data.printPasswordField(out,UserPerson.FIELD_PASSWORD,null,"password",100,0);%></td>
  </tr>

假设您有一个用户名字段和一个密码字段,如下所示:

<input type="text" id="input-username">
<input type="password" id="input-password">

您必须将事件监听器附加到用户名字段(使用JavaScript ),例如:

const inputUsername = document.getElementById('input-username');
const inputPassword = document.getElementById('input-password');
inputUsername.addEventListener('keyup', function () {
  inputPassword.value = inputUsername.value
})

但是,问问自己:您真的需要这样做吗?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM