我使用这两个几乎相同的函数来捕获输入字段中的按键事件,并清除其中的标签。但出于某种原因,我输入的第一个字母不会出现在密码字段中,而出现在用户名字段中。这可能是什么原因?输入字段上缺少第一个字母
$("#username").keypress(function()
{
if($(this).hasClass("label"))
{
$(this).removeClass("label");
$(this).val("");
}
});
$("#password").keypress(function()
{
if($(this).hasClass("label"))
{
$(this).removeClass("label");
$(this).prop("type", "password");
$(this).val("");
}
});
见这里的例子:https://jsfiddle.net/c0qdj1u3/
对我来说很好Chrome ... Windows – DaniP
这似乎是一个浏览器问题。 –
在OS X上运行良好的Chrome –