【问题标题】:Hide placeholder test onfocus on firefox browser在firefox浏览器上隐藏占位符测试onfocus
【发布时间】:2014-03-15 10:31:56
【问题描述】:

我使用 HTML5 占位符属性来标记表单元素。

我希望隐藏占位符 onfocus 事件,但在 Firefox 中,它仅在用户开始键入时才会消失。

当我使用以下样式时,它适用于所有其他网络浏览器

[placeholder]:focus::-webkit-input-placeholder {
  color: transparent;
}

但不是在最新版本的 Firefox 上。

如何在firefox浏览器上隐藏占位符onfocus?

【问题讨论】:

    标签: javascript jquery css html


    【解决方案1】:

    您也有 jQuery 选项。试试这个:

    var placeholderValue = "";
    $('input').focus(function () {
      placeholderValue = $(this).attr('placeholder'); // save the value
      $(this).attr('placeholder', ''); // remove the value for that
    }
    $('input').blur(function () {
      $(this).attr('placeholder', placeholderValue); // update the value! :)
    }
    

    并为此做计数器,当发生模糊事件时,将其返回其值!

    更新小提琴:http://jsfiddle.net/afzaal_ahmad_zeeshan/nHYhK/1/

    我已经在我的 Firefox 中进行了测试 :-) 效果很好!

    【讨论】:

    • 这确实有效,但是当你聚焦和聚焦时,价值就永远失去了。这就是我尝试使用 css 的原因
    • @JaganK 你去 :) 我已经更新了小提琴并添加了代码来存储值:)
    • 我正在考虑使用focusout功能,你觉得blur更好吗?
    • 我没有完美的答案,但你可以从这里得到答案:stackoverflow.com/questions/8973532/… :) 祝你好运!
    【解决方案2】:

    moz 用于 mozilla

    块引用

    input:-moz-placeholder { color:transparent; }

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-10-01
      • 2021-03-23
      • 1970-01-01
      • 2019-10-05
      • 1970-01-01
      • 2016-10-14
      • 1970-01-01
      • 2011-04-25
      相关资源
      最近更新 更多