2009-12-28 87 views
0

所有,jQuery的野清晰

我在我的文本区域场。如何做它,我清楚内容的总和的onclick使用jQuery

感谢。

回答

3
$('textarea').focus(function() { 
    $(this).val(''); 
}); 

这(使用鼠标点击或键盘)清除焦点textarea的。

3
$("#textArea").click(function(){ $(this).attr({ value: '' }); }); 

与几个需要注意的地方:

  • ,它会清除只要有人点击就可以了,即使他们已经进入已经数据
  • ,如果有人点击了它只会工作现场
+1

或者,'$(this).val(“”)'。 – 2009-12-28 07:51:36

+1

'$(this).attr({value:''});'也可以表示为'$(this).val('')'。 – 2009-12-28 07:52:30

2

这将清除onclick的默认值并恢复onblur。

$('textarea').click(function() { 
    if (this.value == this.defaultValue) { 
     this.value = ''; 
    } 
}); 
$('textarea').blur(function() { 
    if (this.value === '') { 
     this.value = this.defaultValue; 
    } 
});