javascript 在提示框中输入类型密码

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

Placing an input of type password in prompt box

javascript

提问by Sarah

Hello guys I know that is probably a stupid question but i had to be sure after all. Can i add an input of type password in a prompt box? prompt box is a one of javascript's Popup boxes.(Alert,Confirm and Prompt)

大家好,我知道这可能是一个愚蠢的问题,但毕竟我必须确定。我可以在提示框中添加密码类型的输入吗?提示框是 javascript 的弹出框之一。(警报、确认和提示)

回答by Oded

No, you can't.

不,你不能。

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

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

As the documentationshows, you can only supply a message and default text.

文档所示,您只能提供消息和默认文本。



You can use javascript to create your own overlay that simulates a prompt popup.

您可以使用 javascript 来创建自己的叠加层来模拟提示弹出窗口。

See the jQuery UI Dialogfor ideas and examples.

有关想法和示例,请参阅 jQuery UI对话框

回答by T.J. Crowder

If you literally mean the promptfunction, you can't. What you can do instead is pop up a divor similar above the main content of your page (using absolute positioning and a z-indexvalue) and put the password box in there.

如果你从字面上的意思是prompt功能,你不能。您可以做的是div在页面的主要内容上方弹出一个或类似的内容(使用绝对定位和一个z-index值)并将密码框放在那里。

More in the various answers to these questions:

更多关于这些问题的各种答案:

There are a variety of libraries you can use that will do the hard work for you (not that it's thathard, but still). If you're already using a library like jQuery, Prototype, YUI, Closure, or any of several others, you may find that there's a plug-in designed for use with that library (jQuery UIfor jQuery, for instance). If not, there are plenty of stand-alone implementations. Look for "light box" or "lightweight window" or "JavaScript dialog box", etc.

您可以使用多种库来为您完成繁重的工作(并不是说它那么难,但仍然如此)。如果您已经在使用像jQueryPrototypeYUIClosure其他几个库中的任何一个库,您可能会发现有一个专为与该库一起使用而设计的插件(例如jQuery UIfor jQuery)。如果没有,有很多独立的实现。寻找“灯箱”或“轻量级窗口”或“JavaScript对话框”等。

Note that any of these will require a bit of a change to the logic of your code, since promptbrings the browser and your script to a screeching halt until the prompt is dismissed by the user, whereas this mechanism of flying an element over the top of the content is, by its nature, asynchronous.

请注意,其中任何一个都需要对您的代码逻辑进行一些更改,因为prompt会使浏览器和您的脚本停止运行,直到用户取消提示,而这种将元素飞过顶部的机制内容本质上是异步的。