javascript 如何在javascript提示框中输入密码

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23754317/
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-28 01:30:07  来源:igfitidea点击:

how to take input as password in javascript promt box

javascriptjqueryhtml

提问by Engineer

i want to take input password in java script prompt box but it only take input as string which is visible now how i can take input password in same text field. is there any way to change this text field from input type text to password without div

我想在java脚本提示框中输入密码,但它只将输入作为字符串输入,现在我可以在同一个文本字段中输入密码。有什么方法可以在没有 div 的情况下将此文本字段从输入类型文本更改为密码

this is what i have already tried

这是我已经尝试过的

prompt("enter password");

here is example

这是例子

enter image description here

在此处输入图片说明

can any one suggest me how i can do this using j query or java script

任何人都可以建议我如何使用 j 查询或 java 脚本来做到这一点

回答by rajesh kakawat

No, you can't.

不,你不能。

The popup is browser controlled and can't be changed.

弹出窗口由浏览器控制,无法更改。

you can use javascript dialog box for it

你可以使用javascript对话框

HTML CODE

HTML代码

<div id="dialog" title="Basic dialog">
    <input type="password" size="25" />
</div>

JAVASCRIPT CODE

爪哇代码

 $( "#dialog" ).dialog();

DEMO

演示

回答by Justus Romijn

promptis native browser functionality, and therefore not very flexible. Unfortunately, you cannot mask the input from a prompt.

prompt是本机浏览器功能,因此不是很灵活。不幸的是,您无法屏蔽提示中的输入。

Alternatively, you can use the input element with the password type:

或者,您可以使用带有密码类型的输入元素:

<input type="password" size="25" />

And show this in a custom modal window. An input element with the type="password"attribute set, will automatically mask the entered characters. On how to embed this in a modal, there are many possibilities. If you are using jQuery, you might want to consider using jQuery UI for this: http://jqueryui.com/dialog/

并在自定义模式窗口中显示此内容。type="password"设置了属性的输入元素将自动屏蔽输入的字符。关于如何将其嵌入到模态中,有很多可能性。如果您使用 jQuery,您可能需要考虑为此使用 jQuery UI:http: //jqueryui.com/dialog/