在firefox浏览器上隐藏占位符测试onfocus

时间:2014-03-15 10:31:57

标签: javascript jquery html css html5

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

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

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

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

但不是最新版本的Firefox。

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

2 个答案:

答案 0 :(得分:0)

你也有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中测试了:-)而且它完美无缺!

答案 1 :(得分:0)

使用mozilla的moz

  

块引用

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

相关问题