如何为用户名选择onfocus时如何更改密码值?

时间:2013-08-30 00:54:03

标签: javascript html

这是我的HTML:

<div class="col">
    <input type="text" id="username" name="username" onfocus="if (this.value=='Email') this.value = ''" onblur="if (this.value=='') this.value = 'Email'" value="Email" /> 
</div>
<div class="col">
    <input type="password" id="password" name="password" value="password" onkeypress="onEnterLogin(event);" /> 
</div>

如果选择用户名文本字段,如何更改密码值?

1 个答案:

答案 0 :(得分:1)

@minitech:谢谢!这就是我所做的,它完美无缺。

<div class="col">
    <input type="text" id="username" name="username" onfocus="if (this.value=='Email') this.value = ''; document.getElementById('password').value = '';" onblur="if (this.value=='') this.value = 'Email'; document.getElementById('password').value = 'password';" value="Email" /> 
</div>
<div class="col">
    <input type="password" id="password" name="password" value="password" onkeypress="onEnterLogin(event);" /> 
</div>