我正在尝试1)当用户关注它时删除textarea中的默认文本.2)如果他没有输入任何内容并点击,则应重新插入默认文本.
下面的代码处理案例#1,但Chrome和Safari(但不是Firefox)中的案例#2失败了.当我输入文本(所以$(this).html().length> 0)然后单击时,jQuery错误地确定$(this).html().length == 0,因此它删除了输入的文本和重新插入默认文本.
jQuery(document).ready(function inputHide(){
$('textarea').each(function(){
var this_area = $(this);
var this_area_val;
this_area_val = this_area.html();
this_area.focus(function(){
if(this_area.html() == this_area_val){
this_area.html('');
}
}).blur(function(){
if(this_area.html().length == 0){
this_area.html(this_area_val);
}
});
});
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助.