简体   繁体   English

如何复制输入字段值(类型=密码)?

[英]How to copy input field value (type=password)?

How to copy the value of input field [type=password]?如何复制输入字段[type=password]的值?

This is my scenario ,I need to copy the value of password field and paste them in confirm password field in my signup page.这是我的场景,我需要复制密码字段的值并将它们粘贴到我的注册页面的确认密码字段中。

Password: <input type="password" name="pwd">
Confirm Password: <input type="password" name="Confirmpwd">

Actually,my question is how to copy the value in input field.(Using:ctrl+c or mouse right click copy option)实际上,我的问题是如何复制输入字段中的值。(使用:ctrl+c 或鼠标右键单击复制选项)

   // get the 2 elements
    var p1 = document.querySelector('input[name="pwd"]');

    var p2 = document.querySelector('input[name="Confirmpwd"]');

      // assign onchnage handler
       p1.onchange = function(){
       //get p1 value
        var val = this.value;
       // assign val to p2
        p2.value = val;
    };

The Copy/Past should not be happen in the password field type for security reasons, the logic is to confirm that you enter the password two times correctly without copy and past it again!出于安全原因,密码字段类型中不应发生复制/过去,逻辑是确认您正确输入了两次密码,无需复制并再次粘贴!

Any way you may copy the value using the following code:您可以使用以下代码以任何方式复制值:

var input = document.getElementById('pwd');
var password = input.value;
text.value=password ;

I strongly advice you to not do this, and let the user to insert the password and confirm it again.我强烈建议你不要这样做,让用户输入密码并再次确认。

// GET THE VALUE
var pw = $('input[name=pwd]').val();
// SET IT IN THE OTHER INPUT
$('input[name=Confirmpwd]').val( pw );

The cuestion here is, ¿Why?这里的提示是,¿为什么? , that's not a "confirmation", just a copy/paste. ,这不是“确认”,只是复制/粘贴。

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

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