最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - display asterisk instead of no value in password field - Stack Overflow

programmeradmin0浏览0评论

I would like to display asterisk instead of no value in password field. When I am setting up the field as type=text then I can see the plain text. When I set the type as password then I am getting blank field. Is there a way to display the value as asterisks?

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

This is the field I have. Thanks in advance, Laziale

I would like to display asterisk instead of no value in password field. When I am setting up the field as type=text then I can see the plain text. When I set the type as password then I am getting blank field. Is there a way to display the value as asterisks?

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

This is the field I have. Thanks in advance, Laziale

Share Improve this question asked Apr 30, 2013 at 21:57 LazialeLaziale 8,23548 gold badges155 silver badges271 bronze badges 4
  • Maybe it's time to update your browser, as mine shows the password fields just like expected -> FIDDLE – adeneo Commented Apr 30, 2013 at 22:00
  • Maybe I didnt get something in your question but why you cant just add a fake value to the input type="password" to display asterisk ? – RafH Commented Apr 30, 2013 at 22:00
  • Are you trying to replace the characters with asterisks as the user types them? – Dan-Nolan Commented Apr 30, 2013 at 22:02
  • Why are you not using type="password"? why reinvent the wheel? – epascarello Commented Apr 30, 2013 at 22:05
Add a ment  | 

2 Answers 2

Reset to default 4

You can use the HTML5 placeholder attribute:

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

Example: http://jsfiddle/AJ2kn/

If you want the user's text input to be replaced by asterisks you need to use a password input—a text input just won't do it:

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

However, the default value will be blank (this applies to text input as well). If you want to initialize this to a default value, you can do it like this:

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

Note: I highly remend not putting a users' password as the default value of a password field! It may promise your users' password.

If you want to display some asterisks as placeholder text when the field is empty you can do that with with the placeholder attribute (again, this applies to text input as well):

<input type="password" placeholder="*****" id="txtPwd" runat="server" />
发布评论

评论列表(0)

  1. 暂无评论