Javascript 密码字段的问题

Javascript 密码字段的问题,javascript,fonts,passwords,password-protection,Javascript,Fonts,Passwords,Password Protection,我有一个密码字段,其值设置为“password”。我有一些非常简单的javascript,将值设置为“”onfocus。我希望密码被屏蔽掉,像往常一样用圆点代替。问题是,如果我将该字段设为密码字段,则原始值“password”将显示为点。有没有简单的方法可以让原始值变成“Password”,其他值在onfocus之后变成点?或者我需要在onfocus之后将字体也更改为只包含点的自定义字体吗 这是我的HTML: <!DOCTYPE html> <html> <head

我有一个密码字段,其值设置为“password”。我有一些非常简单的javascript,将值设置为“”onfocus。我希望密码被屏蔽掉,像往常一样用圆点代替。问题是,如果我将该字段设为密码字段,则原始值“password”将显示为点。有没有简单的方法可以让原始值变成“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>

总和按钮S DOe
请输入密码


这将更简单,只需使用type='password':

<input id="password" type="password" value="Password" />

这不需要JavaScript。使用属性。最坏的情况是,它不受支持,字段将为空。(尽管如此,这是一件好事)


最好的方法是使用占位符,正如图菲在回答中所说的那样

如果要以开始的方式执行此操作,请将type属性更改为在文本和密码之间切换:

<input id="password" type="textbox" value="Password" onfocus="if (this.value=='Password') { this.value='';this.setAttribute('type','password')};" onblur="if (this.value=='') { this.value='Password';this.setAttribute('type','text'); }"/>


在这里摆弄:

只是想知道,有没有办法改变占位符文本的颜色/透明度?