【问题标题】:How to make the type of input password when the user actually selects the input box?用户实际选择输入框时如何设置输入密码的类型?
【发布时间】:2012-04-26 00:09:57
【问题描述】:

这是我已有的代码。当该框处于非活动状态时,它会显示文本“密码”。我想选择框时,它会删除“密码”文本,并将用户输入输入的点作为密码字段。

<div class="custom"><input type="text" class="custom" size="12" value="Password" onfocus="if(this.value == 'Password') { this.value = ''; }" onblur="if(this.value == '') { this.value = 'Password'; }"/></div>

【问题讨论】:

    标签: html forms passwords


    【解决方案1】:

    你可以通过JS改变类型,就像你改变值一样:

    <input type="text" class="custom" size="12" value="Password" onfocus="if(this.value == 'Password') { this.type = 'password'; this.value = ''; }" onblur="if(this.value == '') { this.type = 'text'; this.value = 'Password'; }"/>
    

    【讨论】:

      【解决方案2】:

      如果我理解正确,您只是在寻找:

      this.type = 'password'
      

      反之:

      this.type = 'text'
      

      【讨论】:

        【解决方案3】:

        您应该首先将输入的类型设置为“密码”。如果要在值中显示字段的标签,我建议使用JQuery watermark。它有效地完成了我认为您试图编码的事情,但永远不会提交“密码”一词作为表单字段的值。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-07-09
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多