The input password input box is displayed as an asterisk "*"

The input password box is displayed as an asterisk "*"

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>input密码框显示为星号“*”</title>
    </head>
    <body>
        <!--type需设置为text-->
        <input type="text" />
    </body>
</html>
<script type="text/javascript" src="jquery-3.2.1.js" ></script>
<script>
    var str='';  //定义一个空变量用来存储密码
    $('input').keyup(function(){
        var value=$(this).val();   //输入的时候获取输入框的值  
        str+=value.substr(value.length-1,1); //获取最后一个字符加到到str,因为除了最后一个字符,其他的已经为*
        $(this).val(value.replace(/./g,'*')) //输入框内容全部变为*
        console.log(str); //str即为输入框的内容
    })
</script>

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324832106&siteId=291194637