我想显示输入[type =“password”]的文本框的占位符文本(输入密码)。现在我试图改变input [type =“password”] to input [type =“text”]来显示占位符,如果用户点击文本框我再次改变input [type = “text”]至input [type =“password”]。这不工作请检查脚本
我jsfiddle is here安装文本框输入的地方持有人[type =“密码”]
function setupPasswordPlaceholder(thisEl)
{
if('' !== thisEl.attr("alt"))
{
if('' === thisEl.val())
{
thisEl.val(thisEl.attr("alt"));
thisEl.removeAttr("type");
thisEl.attr('type','text');
thisEl.css({'font-weight':'normal','font-size':'10pt','color':'#999','font-family': '"lucida grande", tahoma, verdana, arial, sans-serif'});
}
thisEl.focus(function()
{
if(thisEl.val() == thisEl.attr("alt"))
{
thisEl.val("");
thisEl.removeAttr("type");
thisEl.attr('type','password');
thisEl.css({'color': '#18A505','font-size': '10pt','font-weight':'normal'});
}
});
thisEl.focusout(function()
{
if('' === thisEl.val())
{
thisEl.val(thisEl.attr("alt"));
thisEl.removeAttr("type");
thisEl.attr('type','text');
thisEl.css({'font-weight':'normal','font-size':'10pt','color':'#999','font-family': '"lucida grande", tahoma, verdana, arial, sans-serif'});
}
});
}
}
$("input[type='password']").each(function(){
setupPasswordPlaceholder($(this));
});
HTML5为输入框添加了一个占位符属性。这不适合你吗? '''' –
对不起,我正在使用html4,在这里没有选项,ie6,ie7不支持html5 –
DOM不是很友好当试图更改输入元素的类型属性时。我最后一次使用它时,只有在从DOM中分离元素,更改属性并重新附加属性时才成功。这是一个黑客最好的。 –