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
但我希望它是用 jQuery 制作的.
But I wish it made in jQuery.
<textarea id="textarea">This should be removed..</textarea>
推荐答案
我使用它作为它更通用的一点 - 它会清除焦点上的元素值,但如果为空,则将元素的值返回为默认值.
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屋!
查看全文