javascript 如何编写一个弹出窗口将密码传递给主窗口?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17480321/
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
How to write a popup window to pass the password to main window?
提问by hoang nguyen
I know that we can use these line of codes as below to pass a password to main window in html:
我知道我们可以使用下面的这些代码行将密码传递给 html 中的主窗口:
var password ;
password = prompt('<fmt:message key="ipack.delete.password"/>','');
if (password){
document.location = link+ "&pw="+password;
}
But, the problem is that if I use "prompt", the input field to type password will not be rendered such as password input. I want to hide the characters in password like **. Could you please help me to solve it?
但是,问题是如果我使用“提示”,输入密码的输入字段将不会被呈现,例如密码输入。我想隐藏密码中的字符,如**。你能帮我解决吗?
Thanks a lot,
非常感谢,
回答by loxxy
Here is a Demoof how you could proceed for a custom popup & get the password:
这是一个演示如何进行自定义弹出窗口并获取密码:
HTML:
HTML:
<div id="popup">
<div>Enter Password:</div>
<input id="pass" type="password"/>
<button onclick="done()">Done</button>
</div>
<button onclick="showPopup()">Show Popup</button>
STYLE:
风格:
#popup {
width:160px;
height:80px;
padding:20px;
background-color:gray;
position:absolute;
top:100px;
left:100px;
display:none;
}
SCRIPT:
脚本:
function done() {
document.getElementById("popup").style.display = "none";
var password = document.getElementById("pass").value;
//DO STUFF WITH PASSWORD HERE
};
function showPopup() {
document.getElementById("popup").style.display = "block";
}