jQuery占位符,显示占位符,直到键入文本为止 [英] jQuery placeholder that shows the placeholder until text is typed

查看:119
本文介绍了jQuery占位符,显示占位符,直到键入文本为止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请注意占位符如何在Stackoverflow上工作,并询问问题标题和Twitter的注册"表单: https://twitter.com /signup

notice how the placeholder works on the Stackoverflow ask a question title and on Twitter's Sign Up form: https://twitter.com/signup

占位符有两种状态:

  1. 未选择(显示占位符)
  2. 已选择,但输入为0(显示了占位符,颜色较浅)

有人知道支持此功能的jQuery插件吗?我见过jQuery占位符插件支持#1,但不支持#2.

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

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆