【问题标题】:Hide placeholder value with JQuery使用 JQuery 隐藏占位符值
【发布时间】:2013-06-05 05:07:29
【问题描述】:

我有很多带有一些文本输入的模板,如下所示:

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

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

【问题讨论】:

  • 我建议推迟这个。不同的浏览器在不同的时间隐藏占位符文本——有些是在点击字段时,有些是在用户开始输入时——与占位符在其他网站上为用户工作的方式保持一致是一种美德。

标签: jquery placeholder


【解决方案1】:

试试这个:{检查是否跨浏览器}

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'));
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-02-16
    • 1970-01-01
    • 1970-01-01
    • 2016-09-14
    • 2013-02-07
    • 2017-05-16
    • 2014-09-11
    • 1970-01-01
    相关资源
    最近更新 更多