【问题标题】:Password Box Text密码框文本
【发布时间】:2012-08-22 01:47:05
【问题描述】:

目前我的网站有一个登录框。我想在密码框中添加文本以告诉用户使用哪个密码。 IE。密码框将包含文字(请使用 windows 登录密码),当他们点击它时,文字将消失并允许他们输入密码。
我可以使用这样的登录框来做到这一点:

<asp:TextBox ID="UserName" class="txtbox" runat="server" text="NUID" Width="240px"
 onfocus="if(this.value==this.defaultValue) {this.value='';$(this).css('color','black');}"  
 onblur="if(this.value=='') {this.value=this.defaultValue;$(this).css('color','rgb(173,180,195)');}"></asp:TextBox>

但是,使用密码似乎不起作用。这似乎是由于它具有 textmode="password" 参数。

有谁知道如何在密码模式下使用 ASP.NET 文本框执行此操作。不是 HTML 文本框。

这是我当前的代码。

HTML

<asp:Login ID="Login1" class="loginbox" runat="server" Font-Names="Verdana" Font-Size="8pt" 
      DisplayRememberMe="False" UserNameLabelText="NUID:" 
      FailureText="Incorrect login. Please try again."  TitleText="" DestinationPageUrl="default.aspx" onauthenticate="Login1_Authenticate">
      <TextBoxStyle Width="110px" />
      <LoginButtonStyle Font-Names="Arial, Helvetica, sans-serif" Height="24px" />
                                        <LayoutTemplate>
                                            <table border="0" cellpadding="1" cellspacing="0" 
                                                style="border-collapse:collapse; height:113px">
                                                <tr>
                                                    <td>
                                                        <table border="0" cellpadding="0"> 
                                                            <tr>
                                                                <td valign="baseline">
                                                                <div class="textlogin">NUID</div>
                                                                </td>
                                                            </tr>                                                               
                                                            <tr>
                                                                <td>
                                                                    <asp:TextBox ID="UserName" class="textloginbox" runat="server"  Font-Bold="true"></asp:TextBox>
                                                                    <asp:RequiredFieldValidator ID="UserNameRequired" runat="server" 
                                                                        ControlToValidate="UserName" ErrorMessage="User Name is required." 
                                                                        ToolTip="User Name is required." ValidationGroup="Login1" ForeColor="#FF0000" Font-Bold="true" Font-Size="14px">*</asp:RequiredFieldValidator>
                                                                </td>
                                                            </tr>
                                                            <tr><td style="height:3px;"></td></tr>
                                                            <tr>
                                                                <td>
                                                                <div class="textlogin">Password</div>
                                                                </td>
                                                            </tr>  
                                                            <tr>
                                                                <td>

                                                                    <asp:TextBox ID="Password" runat="server" class="textloginbox" TextMode="Password" Font-Bold="true"></asp:TextBox>
                                                                    <asp:RequiredFieldValidator ID="PasswordRequired" runat="server" 
                                                                        ControlToValidate="Password" ErrorMessage="Password is required." 
                                                                        ToolTip="Password is required." ValidationGroup="Login1" ForeColor="#FF0000" Font-Bold="true" Font-Size="14px">*</asp:RequiredFieldValidator>
                                                                </td>
                                                            </tr>
                                                            <tr>
                                                                <td align="center" style="color:#DA6426;">
                                                                    <asp:Literal ID="FailureText" runat="server" EnableViewState="False"></asp:Literal>
                                                                </td>
                                                            </tr>
                                                            <tr>
                                                                <td align="right">
                                                                <asp:ImageButton ID="LoginButton" runat="server" CssClass="loginbutton" CommandName="Login" ValidationGroup="Login1"  ImageUrl="~/Icons/Enter Arrow 30.png" />
                                                                &nbsp;&nbsp;       
                                                                </td>
                                                            </tr>
                                                        </table>
                                                    </td>
                                                </tr>
                                            </table>
                                        </LayoutTemplate>
                                    <TitleTextStyle BackColor="#FFFFE0" Font-Bold="True" 
                                        ForeColor="#FFFFFF" Height="0px"/>
                                    </asp:Login>

【问题讨论】:

  • TextMode="Password" 将呈现为密码输入。您不希望用户阅读您在******** 中设置的内容,对吗?
  • 是的。这就是为什么我想知道是否有办法使用 textmode="password" 来做到这一点。也许让 jquery 改变它什么的。

标签: javascript asp.net html textbox login-control


【解决方案1】:

你试过占位符属性吗?所以在 ID="Password" 之后,放入 placeholder="Enter Test Here"。它不适用于 IE8 及以下版本...试试这个(使用 jQuery)

$("#Password").focus(function()
{
    if($(this).val() == "Your Text Here")
    {
        $(this).val("");
    }
});

$("#Password").blur(function()
{
    if($(this).val() == "")
    {
        $(this).val("Your Text Here");
    }
});

编辑:阅读完上面的评论后,他有一点。使用此代码将使“您的文本在此处”不可读。但是,placeholder 属性会正确显示,即使不是 IE 8 及以下版本

【讨论】:

  • 感谢您的建议。我们需要为 ie7 及更高版本开发。可怕的规则。是的。我理解关于 textmode="Password" 的事情。只是想知道是否有办法解决它。
猜你喜欢
  • 2013-03-10
  • 2013-06-03
  • 2012-05-04
  • 2014-05-22
  • 2012-03-17
  • 2015-04-19
  • 1970-01-01
  • 2023-03-27
  • 2014-06-11
相关资源
最近更新 更多