我在网上发现了类似的问题,但没有可行的解决方案。
正如标题所示,我的问题是如何利用 jQuery 或 Javascript 创建一个密码提示例如,当单击按钮时。
因此,以下内容不是显示文本,而是希望文本字段充当密码字段。
var pass1 = 'hello123';
password=prompt('Please enter password to view page')
if (password==pass1)
alert('password correct! Press ok to continue.')
我想要类似于下图的东西。!
您可以做的一件事(就像@David提到的那样)是使用模型窗口或子窗口来生成要填写的表单。
HTML
<!DOCTYPE Html />
<html>
<head>
<title></title>
</head>
<body>
<input type="button" id="prompt" value="Click for authentication prompt"/>
<script type="text/javascript" src="theJS.js"></script>
</body>
</html>
脚本语言
var theButton = document.getElementById("prompt");
theButton.onclick = function () {
var thePrompt = window.open("", "", "widht=500");
var theHTML = "";
theHTML += "<p>The server http://localhost:8888 requires a username and password. The server says: These are restricted files, please authenticate yourself.</p>";
theHTML += "<br/>";
theHTML += "Username: <input type='text' id='theUser' placeholder='Enter Username...'/>";
theHTML += "<br />";
theHTML += "Password: <input type='text' id='thePass' placeholder='Enter Password...'/>";
theHTML += "<br />";
theHTML += "<input type='button' value='OK' id='authOK'/>";
thePrompt.document.body.innerHTML = theHTML;
var theUser = thePrompt.document.getElementById("theUser").value;
var thePass = thePrompt.document.getElementById("thePass").value;
thePrompt.document.getElementById("authOK").onclick = function () {
doAuthentication(theUser, thePass);
}
}
function doAuthentication(user, pass) {
//do authentication
}
显然,如果您想要与正在使用的窗口具有相同的外观和感觉,您将需要应用一些 CSS 和 JavaScript 来使其更加“漂亮”,以便它反映您想要的内容。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)