jQuery:单击时会显示textarea默认值 [英] jQuery: textarea default value disppear on click
本文介绍了jQuery:单击时会显示textarea默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想要一个带有一些默认文本的文本区域.当用户单击文本区域时 默认文本应删除.如何使文本区域的价值在点击时消失?
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?
我希望它完全像这样, http://www.webune.com/forums/20101025cgtc .html
I want it exactly like this, http://www.webune.com/forums/20101025cgtc.html
但是我希望它是用jQuery制造的.
But I wish it made in jQuery.
<textarea id="textarea">This should be removed..</textarea>
推荐答案
我将其用作通用名称-它将清除焦点上的元素值,但如果为空则将元素的值恢复为默认值. /p>
I use this as its a bit more generic - it will clear out the element's value on focus, but return the element's value to the default value if empty.
$("#textarea")
.focus(function() {
if (this.value === this.defaultValue) {
this.value = '';
}
})
.blur(function() {
if (this.value === '') {
this.value = this.defaultValue;
}
});
这篇关于jQuery:单击时会显示textarea默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文