相关疑难解决方法(0)

使用jQuery更改输入字段的类型

$(document).ready(function() {
    // #login-box password field
    $('#password').attr('type', 'text');
    $('#password').val('Password');
});
Run Code Online (Sandbox Code Playgroud)

这应该更改正常文本字段的#password输入字段(with id="password"),type password然后填写文本"Password".

但它不起作用.为什么?

这是表格:

<form enctype="application/x-www-form-urlencoded" method="post" action="/auth/sign-in">
  <ol>
    <li>
      <div class="element">
        <input type="text" name="username" id="username" value="Prihlasovacie meno" class="input-text" />
      </div>
    </li>
    <li>
      <div class="element">
        <input type="password" name="password" id="password" value="" class="input-text" />
      </div>
    </li>
    <li class="button">
      <div class="button">
        <input type="submit" name="sign_in" id="sign_in" value="Prihlási?" class="input-submit" />
      </div>
    </li>
  </ol>
</form>
Run Code Online (Sandbox Code Playgroud)

javascript jquery html-input

200
推荐指数
9
解决办法
29万
查看次数

使用JavaScript更改IE中的<input>类型

以下代码适用于所有Web浏览器,除了IE:

<input type="text" name="passwordLogin" value="Password" onfocus="if(this.value=='Password'){this.value=''; this.type='password'};" onblur="if(this.value==''){this.value='Password'; this.type='text'};" size="25" />
Run Code Online (Sandbox Code Playgroud)

如何为IE修复它?

我做了一些更改,但仍然有错误.

我希望它像这样工作:

<input type="text" name="usernameLogin" value="Email" onfocus="if(this.value=='Email'){this.value=''};" onblur="if(this.value==''){this.value='Email'};" size="25" />
Run Code Online (Sandbox Code Playgroud)

如果我不输入任何东西,它会把价值放回去.

所以我尝试了这个:

<td colspan="2" id="passwordLoginTd">
     <input id="passwordLoginInput1" type="text" name="passwordLogin" value="Password" onfocus="passwordFocus()" size="25" />
     <input id="passwordLoginInput2" style="display: none;" type="password" name="passwordLogin" value="" onblur="passwordBlur()" size="25" />
    </td>
    <script type="text/javascript">
    //<![CDATA[

     passwordElement1 = document.getElementById('passwordLoginInput1');
     passwordElement2 = document.getElementById('passwordLoginInput2');

     function passwordFocus() {

      passwordElement1.style.display = "none";
      passwordElement2.style.display = "inline";
      passwordElement2.focus();

     }

     function passwordBlur() {

      if(passwordElement2.value=='') {

       passwordElement2.style.display = "none";
       passwordElement1.style.display = "inline";
       passwordElement1.focus(); …
Run Code Online (Sandbox Code Playgroud)

html javascript internet-explorer

9
推荐指数
2
解决办法
2万
查看次数

Javascript IE6/7/8更改输入类型

以下javascript代码段将更改INPUT的类型,例如从文本更改为密码.它用于允许用户在键入时在屏幕上显示其密码:

document.save_form.password_confirm.type= 'text';
...
document.save_form.password_confirm.type= 'password';
Run Code Online (Sandbox Code Playgroud)

这在FF/Chrome中效果很好,但在IE6/7/8中我收到"不支持此命令"错误消息.

html javascript internet-explorer

2
推荐指数
1
解决办法
2789
查看次数

Javascript更改输入类型动态无法在IE8上运行

我有一个输入字段用于在网页中输入密码:

<input name="txtPassword" type="text" class="input2" id="txtPassword" value="Password" onfocus="txtOnFocus2('txtPassword','Password');" onblur="txtOnBlur2('txtPassword','Password');" />
Run Code Online (Sandbox Code Playgroud)

在初始状态下,用户应将"密码"作为初始值读取,当他开始输入密码时,该字段应更改为键入密码.此外,当他将其设置为空白或初始值时,该字段应将类型更改为"文本"并显示密码.

我编写了代码,让它可以在Firefox,Chrome和Safari上运行,并且不会在IE 8上将类型更改为密码.

这是我通过编辑现有功能代码制作的js代码:

 function txtOnFocus2(elementId, defaultText)
 { 
    if (document.getElementById(elementId).value == defaultText)
    {
       document.getElementById(elementId).value = "";
  document.getElementById(elementId).type = "password";
    }
 }

 function txtOnBlur2(elementId, defaultText)
 {
    var textValue = document.getElementById(elementId).value;

    if (textValue == defaultText || textValue.length == 0)
    {
      document.getElementById(elementId).type = "text"; 
  document.getElementById(elementId).value = defaultText;
    }
 }
Run Code Online (Sandbox Code Playgroud)

这在Firefox,Chrome和Safari中运行良好,但不会改变IE 8上的字段类型.

html javascript

2
推荐指数
1
解决办法
2万
查看次数

密码为文本而不是点。

您可以将 a 显示Form::password为文本而不是默认的点/项目符号Laravel吗?

我要这个 没有点 而不是这个 点

php forms laravel-4

-1
推荐指数
1
解决办法
3741
查看次数