在密码字段中显示星号而不是值

时间:2013-04-30 21:57:33

标签: c# javascript asp.net html web

我想在密码字段中显示星号而不是值。 当我将字段设置为type = text时,我可以看到纯文本。当我将类型设置为密码时,我得到空白字段。 有没有办法将值显示为星号?

  <input type="text" id="txtPwd" runat="server" />           

这是我的领域。 在此先感谢Laziale

2 个答案:

答案 0 :(得分:4)

您可以使用HTML5 placeholder属性:

 <input type="password" placeholder="●●●●●●●●●">

示例:http://jsfiddle.net/AJ2kn/

答案 1 :(得分:2)

如果您希望用星号替换用户的文本输入 以使用password输入 - text输入,则不会这样做:

<input type="password" id="txtPwd" runat="server" />

但是,默认值为空(这也适用于text输入)。如果要将其初始化为默认值,可以这样做:

<input type="password" value="dummy" id="txtPwd" runat="server" />

注意:我强烈建议将用户密码作为密码字段的默认值!它可能会损害用户的密码。

如果要在字段为空时显示一些星号作为占位符文本,则可以使用placeholder属性执行此操作(同样,这也适用于text输入):

<input type="password" placeholder="*****" id="txtPwd" runat="server" />