简体   繁体   English

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

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

I know this is easy but I want to make the password automatically be entered as the same thing as the username but I cant get it to copy right in real time. 我知道这很容易,但是我想使密码和用户名一样自动输入,但是我无法实时复制它。

<%=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>

Let's say you have a username field and a password field like these: 假设您有一个用户名字段和一个密码字段,如下所示:

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

You have to attach an event listener to the username field (using JavaScript ), eg like this: 您必须将事件监听器附加到用户名字段(使用JavaScript ),例如:

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

However, ask yourself: do you really need to do this? 但是,问问自己:您真的需要这样做吗?

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

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