javascript 使用javascript从密码类型文本框中获取值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8904246/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 04:55:55  来源:igfitidea点击:

Getting value from password type textbox with javascript

javascripthtmlinputpasswords

提问by Beanno1116

I am just trying for experimental purposes to get the value of an input text box with the type password using this format

我只是出于实验目的尝试使用这种格式获取带有类型密码的输入文本框的值

    var Passt = document.getElementById('pass');
        var Name = document.getElementById('fName');
        var userPass = Passt.value;
        var userName = Name.value;

and the html input is as follows

并且html输入如下

    <input class="textBox" id="pass" type="password" maxlength="30" required/>

I know there are better and more secure ways but I'm just beginning and would like to know. Thank you in advance.

我知道有更好、更安全的方法,但我才刚刚开始并想知道。先感谢您。

回答by Naveen Kumar

If you want to get the password at server side for example in PHP, the value is posted using the name attribute <input type="password" id="pass" name="pass" required />. In PHP

如果您想在服务器端获取密码,例如在 PHP 中,则使用 name 属性发布该值<input type="password" id="pass" name="pass" required />。在 PHP 中

$password=$_REQUEST['pass'];

$password=$_REQUEST['pass'];

will give you the password

会给你密码

The above JavaScript code is correct if you want to check if you want to check if you have got the value use alert on that field

上面的 JavaScript 代码是正确的,如果您想检查是否要检查您是否在该字段上获得了值 use alert

回答by SLaks

That is the correct way to do it, although jQuery would be shorter.

这是正确的方法,尽管 jQuery 会更短。

There are no additional security issues involved (unless you do something dumb with the password).

不涉及额外的安全问题(除非你对密码做了一些愚蠢的事情)。