我需要在密码字段中显示一些默认文本,例如“输入您的密码”。由于我需要支持 IE7,所以 placeholder 属性在这里没有解决方案。我使用了 onfocus 和 blur 但它在 Internet Explorer 中不起作用。
<input type="text" value="Enter the password" id="fieldPassword" onfocus="showPass()" onblur="hidePass()"/>
function showPass()
{
var pass = document.getElementById('fieldPassword').value;
if((pass=="Enter the password")||pass=="")
{
document.getElementById('fieldPassword').type="password";
document.getElementById('fieldPassword').value="";
}
else
{
}
}
function hidePass()
{
var pass = document.getElementById('fieldPassword').value;
if(pass=="")
{
document.getElementById('fieldPassword').type="text";
document.getElementById('fieldPassword').value="Enter the password";
}
}