我使用this Jquery plugin来填充输入时点击时消失的文本。它对于密码字段并不理想,因为所有内容都显示为点。在开始键入之前,在密码字段中显示默认文本的好方法是什么?密码字段中的Jquery默认值
3
A
回答
7
通过JS,我的答案会和@endbuster's一样。然而,整个JS路线都很黑,现在开始出现替代方案。许多现代浏览器现在直接通过HTML5支持这件事情:
<input type="password" name="password" placeholder="Enter password"/>
(许多现代浏览器=除Internet Explorer的每一个主要的一个我拒绝了它的代码,如果你必须有在IE浏览器同样的事情为好。 ,你必须走hacky路线。)
1
您可以将输入字段的类型设置为密码。但是,通过页面加载时通过JavaScript将其设置为正常(这样,如果用户没有JS,则可以轻松地回退)。一旦收到点击,将输入字段的类型设置回密码。
1
就像建议的那样,你可以交换输入,但它在IE中不起作用。 IE不会允许它,因为它可能是某种安全漏洞。
我用这个:
/* From: http://grzegorz.frydrychowicz.net/jquery_toggleformtext/
Modified to swap password textbox type so watermark can be read */
$(document).ready(function() {
if (!jQuery.browser.msie) {
$("input:password").each(function() {
if (this.value == '') {
this.type = "text";
}
$(this).focus(function() {
this.type = "password";
});
$(this).blur(function() {
if (this.value == '') {
this.type = "text";
}
});
});
}
$("input:text, textarea, input:password").each(function() {
if (this.value == '') {
$(this).addClass("watermark");
this.value = this.title;
}
});
$("input:text, textarea, input:password").focus(function() {
$(this).removeClass("watermark");
if (this.value == this.title) {
this.value = '';
}
});
$("input:text, textarea, input:password").blur(function() {
if (this.value == '') {
$(this).addClass("watermark");
this.value = this.title;
}
});
$("input:image, input:button, input:submit").click(function() {
$(this.form.elements).each(function() {
if (this.type == 'text' || this.type == 'textarea' || this.type == 'password') {
if (this.value == this.title && this.title != '') {
this.value = '';
}
}
});
});
});
我最后只给了一个正常的密码输入行为的去了。我发现上面的输入交换有点古怪,但你可以尝试一下。
+0
古德剧本!要解决IE浏览器,如何使用show()和hide()隐藏type = text在点击和显示(0类型=密码字段? – CyberJunkie 2011-05-09 19:05:34
相关问题
- 1. 将密码字段中的默认值显示为明文
- 2. django中的用户模型密码字段默认密码字段
- 3. springSecurityService的默认字段值
- 4. Hibernate中嵌入字段的默认值。 java.sql.SQLException:字段'url'没有默认值
- 5. Auth ::尝试将默认密码更改为默认字段,如DB中
- 6. ASP:NET确认密码字段
- 7. 在Magento系统配置中设置密码字段的默认值
- 8. Avro字段默认值
- 9. Sensenet DateTime字段默认值
- 10. Django AdminForm字段默认值
- 11. 选项字段默认值
- 12. Odoo 8 - 默认字段值
- 13. 覆盖默认值字段
- 14. 删除默认的密码值6 password_confirm
- 15. 默认值 - >的TextMode =密码
- 16. 变更集中字段的默认值
- 17. zenity字段中的默认值
- 18. TWTweetComposeViewController中'From:'字段的默认值
- 19. JBoss默认密码
- 20. (Kontakt.io)默认密码?
- 21. jQuery没有获取密码字段值
- 22. 如何在表单输入字段中为密码指定默认值?
- 23. 输入密码字段的默认文本
- 24. 正则表达式的asp.net默认密码字段
- 25. Oracle 11g的默认密码?
- 26. 如何从odoo中的xml代码设置默认字段值?
- 27. 表单字段初始值或默认值的好jQuery插件?
- 28. 值的字段的默认Django管理
- 29. sqlite的插入与默认字段的默认值
- 30. 值java.sql.SQLException:字段“passwordConfirmation”没有默认值
'placeholder'太棒了!我赞扬你放弃资源管理器。 – CyberJunkie 2011-05-09 19:28:39