使用JQuery隐藏占位符值 [英] Hide placeholder value with JQuery

查看:530
本文介绍了使用JQuery隐藏占位符值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有很多模板,带有一些像这样的文本输入:

I have a lot of templates with some text input like this:

<input type="text" autocomplete="off" value="" placeholder="Keywords" name="keywords" id="keywords">

当用户单击字段时,客户要求我隐藏占位符值(示例中的关键字).我不知道如何用JS和JQuery做到这一点.跨浏览器解决方案有没有办法做到这一点?

The client asked me to hide the placeholder value (Keywords in the example) when the user click on the field. I don't know how to do this with JS and JQuery. Is there a way to make this happen with a crossbrowser solution?

推荐答案

尝试以下操作:{检查是否为跨浏览器}

Try this: { check it if cross browser }

http://jsfiddle.net/MDhtj/1

$('input[placeholder]').on('focus', function () {
    var $this = $(this);
    $this.data('placeholder', $this.prop('placeholder')).removeAttr('placeholder')
}).on('blur', function () {
    var $this = $(this);
    $this.prop('placeholder', $this.data('placeholder'));
});

这篇关于使用JQuery隐藏占位符值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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