如何将.js密码设为星号?

时间:2014-01-18 01:16:57

标签: javascript html password-protection

我有一个基本的密码JS代码,但每当我在文本框中输入时,它会显示已键入的内容,而不是密码框中显示的正常星号。我的代码如下。

<!DOCTYPE html>
<html>
<title>
Enter Password
</title>
<body>
<script type="text/javascript">

var password = "THE LIST";
var x = prompt("Enter in the password "," ");
if (x == password) {
  window.location = "index.html";
}
else {
window.location = "bad.htm";
}

</script>
</body>
</html>

注意:我这样做很有趣,我并不愚蠢到使用它来实现真正的保护。

2 个答案:

答案 0 :(得分:3)

您应该使用:<input type="password">

答案 1 :(得分:2)

你不能在提示中这样做。提示是沙箱的浏览器/操作系统的功能。如果您想要控制,则需要在HTML中执行:

<input type="password" />