【发布时间】:2011-10-14 15:58:04
【问题描述】:
我正在为不支持 placeholder 属性的浏览器编写后备代码。我想出的东西在除 IE6 之外的所有浏览器中都能完美运行。
问题是这样的:在聚焦两个字段中的任何一个后,占位符文本按预期消失,但 我无法在字段中键入或粘贴任何文本!有时我会收到“错误84 - 未指定的错误”,但大多数时候根本没有错误。
我已在http://jsfiddle.net/CMWHx/ 以最简单的形式上传了有问题的代码(代码也在下面)
这真的让我发疯了,以至于我开始认为我的 IE6 副本是狡猾的(这是一个 MultipleIE 安装),所以如果你们中的任何人有 IE6 的副本,我将不胜感激可以快速检查上面的链接并确认您遇到了与我相同的问题。
提前致谢:)
HTML
<input id="email_input" type="email" placeholder="Email" required="required" />
<input id="password_input" type="password" placeholder="Password" required="required" />
JavaScript (jQuery 1.6.2)
$("#email_input").val("Email").focus(function() {
if ($(this).val() == "Email")
{
$(this).val("");
}
}).blur(function() {
if ($(this).val() == "")
{
$(this).val("Email");
}
});
$("#password_input").hide().after("<input id=\"password_placeholder\" value=\"Password\" />").blur(function() {
if ($(this).val() == "")
{
$(this).hide();
$("#password_placeholder").show();
}
});
$("#password_placeholder").focus(function() {
$(this).hide();
$("#password_input").show().focus();
});
【问题讨论】:
-
实时链接是一个很好的辅助问题,但也总是发布相关代码在问题中。两个原因。 1.人们不应该通过链接来帮助你。 2. StackOverflow 不仅是为您现在提供的资源,也是为将来遇到类似问题的其他人提供的资源。外部链接可以被移动、修改、删除等。通过确保相关代码在问题中,我们确保问题(及其答案)在合理的时间内保持有用。
-
@T. J. Crowder - 感谢您的评论,我已将代码添加到帖子中
标签: javascript jquery input internet-explorer-6 placeholder