jQuery: textarea default value disppear on click

2019-03-13 14:55发布

I want a textarea with some default text. When the user clicks in the textarea the default text should be deleted. How can I make value of a textarea disappear on click?

I want it exactly like this, http://www.webune.com/forums/20101025cgtc.html

But I wish it made in jQuery.

<textarea id="textarea">This should be removed..</textarea>

8条回答
We Are One
2楼-- · 2019-03-13 15:17

Just try the below snippet. First time you click on the text area it empties the content.

$('#textarea').focus(function(){
 $(this).empty();
});
查看更多
不美不萌又怎样
3楼-- · 2019-03-13 15:24

Very simple non-jQuery-dependent solution:

<textarea onfocus="if(this.value==this.defaultValue)this.value=''" onblur="if(this.value=='')this.value=this.defaultValue">Hello World</textarea>
查看更多
登录 后发表回答