【发布时间】:2013-11-09 15:53:56
【问题描述】:
【问题讨论】:
-
为什么你使用占位符这个你可以使用模糊也占位符是浏览器的内置属性,即不支持这个remeber!
标签: javascript jquery focus placeholder
【问题讨论】:
标签: javascript jquery focus placeholder
尽量用removeAttr()点赞,
$('input,textarea').focus(function(){
$(this).removeAttr('placeholder');
});
要在blur() 上再次获取placeholder value,试试这个,
$('input,textarea').focus(function(){
$(this).data('placeholder',$(this).attr('placeholder'))
.attr('placeholder','');
}).blur(function(){
$(this).attr('placeholder',$(this).data('placeholder'));
});
【讨论】:
placeholder 在IE 8 中不起作用,为此您必须在focus and blur 上设置elements 的value 参见演示jsbin.com/avIfuDAf/3
不需要使用javascript函数来完成这个,一个更简单的解决方案是:
<input type="text" placeholder="enter your text" onfocus="this.placeholder=''" onblur="this.placeholder='enter your text'" />
【讨论】:
CSS 为我工作:
input:focus::-webkit-input-placeholder {
color: transparent;
}
【讨论】:
$("input[placeholder]").each(function () {
$(this).attr("data-placeholder", this.placeholder);
$(this).bind("focus", function () {
this.placeholder = '';
});
$(this).bind("blur", function () {
this.placeholder = $(this).attr("data-placeholder");
});
});
【讨论】:
一个非常简单和全面的解决方案适用于 Mozila、IE、Chrome、Opera 和 Safari:
<input type="text" placeholder="your placeholder" onfocus="this.placeholder=''" onblur="this.placeholder='your placeholder'" />
【讨论】:
$('*').focus(function(){
$(this).attr("placeholder",'');
});
【讨论】:
试试这个希望对你有帮助
$('input,textarea').focus(function()
{
$(this).attr('placeholder','');
});
【讨论】:
$('input').focus(function()
{
$(this).attr('placeholder','');
});
【讨论】:
对于不支持占位符的浏览器,您可以使用:
https://github.com/mathiasbynens/jquery-placeholder。
像 HTML5 一样正常添加占位符属性,然后调用这个插件:$('[placeholder]').placeholder();。然后使用 Rohan Kumar 的代码,将是跨浏览器的。
【讨论】:
这是我点击不聚焦的解决方案:
$(document).on('click','input',function(){
var $this = $(this);
var place_val = $this.attr('placeholder');
if(place_val != ''){
$this.data('placeholder',place_val).removeAttr('placeholder');
}
}).on('blur','input',function(){
var $this = $(this);
var place_val = $this.data('placeholder');
if(place_val != ''){
$this.attr('placeholder',place_val);
}
});
【讨论】: