jQuery 占位符,在输入文本之前显示占位符 [英] jQuery placeholder that shows the placeholder until text is typed
问题描述
注意占位符如何在 Stackoverflow 提问标题和 Twitter 的注册表单上工作:https://twitter.com/注册
notice how the placeholder works on the Stackoverflow ask a question title and on Twitter's Sign Up form: https://twitter.com/signup
占位符有两种状态:
- 未选择(显示占位符)
- 已选择,但输入为 0(显示占位符,颜色较浅)
有谁知道支持这个的 jQuery 插件?我见过支持 #1 但不支持 #2 的 jQuery 占位符插件.
Does anyone know of a jQuery plugin that supports this? I've seen jQuery placeholder plugins that support #1, but not #2.
谢谢
推荐答案
这里有一个快速简单的示例来帮助您入门.
Here is a quick and easy example to get you started.
HTML
<input type='text' id='in' value='Enter Something...'>
JavaScript
$('#in').bind({
click : function() {
$(this).css('color','#ccc');
},
focusout : function() {
$(this).css('color','#000');
},
keydown : function() {
$(this).val('');
$(this).css('color','#000');
$(this).unbind('keydown');
$(this).unbind('click');
},
});
祝你好运
我增加了功能并将其打包为插件,您可以在 Github 获得它,jQuery 插件站点 或来自 项目主页(提供演示和文档)
I increased the functionality and packaged it as a plugin, you can get it at Github, the jQuery Plugin Site or from the Project Home (Demo & Documentation Available)
这篇关于jQuery 占位符,在输入文本之前显示占位符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!