所以我有一个密码字段,其值设置为“密码”。我有一些非常简单的 JavaScript,可以将值设置为“onfocus”。我希望像往常一样将密码屏蔽掉,用点替换。问题是,如果我将该字段设置为密码字段,则原始值“密码”将显示为点。有没有什么简单的方法可以使原始值“Password”和其余的,在onfocus之后,点?或者我是否必须在 onfocus 之后将字体更改为仅点的自定义字体?
这是我的 HTML:
<!DOCTYPE html>
<html>
<head>
<title>SuM BUTtonsS DOe</title>
<link rel="stylesheet" href="buttons.css"/>
</head>
<body>
<p>Please enter the password.</p>
<form>
<input id="password" type="textbox" value="Password" onfocus="if (this.value=='Password') this.value='';" onblur="if (this.value=='') this.value='Password';"/>
</form>
</body>
</html>
最佳答案
您不需要 JavaScript。使用placeholder属性。最坏的情况是,它不受支持并且该字段将为空。 (不过,它是 widely supported now )。
<input id="password" type="password" placeholder="Password">
关于javascript - 密码字段问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29435133/