Jquery 密码字段的默认值
我正在使用 这个 Jquery 插件 用点击时消失的文本填充输入。它对于密码字段来说并不理想,因为所有内容都显示为点。在开始输入之前使默认文本在密码字段中可见的好方法是什么?
I am using this Jquery plugin for populating inputs with text that disappears on click. It isn't ideal for password fields because everything shows up as dots. What would be a good way to make a default text visible in password fields before you start typing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
通过 JS,我的答案将与@ultimatebuster 的相同。然而,既然替代方案开始出现,整个 JS 路线就很糟糕了。现在许多现代浏览器都直接通过 HTML5 支持这个东西:(
许多现代浏览器=除了 Internet Explorer 之外的所有主流浏览器。我拒绝为其编写代码;如果你也必须在 IE 中拥有同样的东西,你就必须去黑客路线。)
Through JS, my answer would be the same as @ultimatebuster's. However, the whole JS route is hacky, now that alternatives started appearing. Many modern browsers now support this thing directly through HTML5:
(Many modern browsers = every major one except the Internet Explorer. I refuse to code for it; if you have to have the same thing in IE as well, you'll have to go the hacky route.)
您可以将输入字段的类型设置为密码。但是,在页面加载时通过 javascript 将其设置为正常(这样,如果用户没有 JS,您可以轻松回退)。一旦收到点击,将输入字段的类型设置回密码。
You could set the type of the input field as password. However, set it to normal via javascript upon page load (this way you can fallback easily if the user doesn't have JS). Once it receives a click, set the type of the input field back to a password.
就像建议的那样,您可以交换输入,但它在 IE 中不起作用。 IE 不允许这样做,因为这可能是某种安全漏洞。
我曾经使用过这个:
我最终放弃了正常的密码输入行为。我发现上面的输入交换有点奇怪,但你可以尝试一下。
Like suggested, you can swap the inputs, but it doesn't work in IE. IE won't allow it since it may be some sort of security hole.
I used to use this:
I finally just gave up an went with the normal password input behavior. I found the above input swapping to be a bit quirky, but you can give it a shot.