我正在尝试更改输入类型,特别是在点击输入更改type ="text"以更改="密码"之后.
我不知道为什么,但我不能添加选项type ="password"作为输入的属性.
$('input#id_reg_pass').removeAttr("type"); #this works, type="text" is removing
$('input#id_reg_pass').attr('type', 'password'); #problem, this not works
$(this).addClass('exampleText').val($(this).attr('title'));
Run Code Online (Sandbox Code Playgroud)
有没有类似的问题?我很高兴每一个提示......谢谢
以下代码适用于所有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)