Jquery字段清除
全部, 我的for中有一个文本区域字段。如何使用jquery在sum onclick上清除它的内容 谢谢Jquery字段清除,jquery,html,Jquery,Html,全部, 我的for中有一个文本区域字段。如何使用jquery在sum onclick上清除它的内容 谢谢 $("#textArea").click(function(){ $(this).attr({ value: '' }); }); 有几个警告: 只要有人点击它,它就会被清除,即使他们已经输入了数据 只有在有人点击现场时,它才会起作用 这将使用鼠标单击或键盘清除焦点上的文本区域。这将清除默认值onclick并恢复onblur $('textarea').click(function ()
$("#textArea").click(function(){ $(this).attr({ value: '' }); });
有几个警告:
只要有人点击它,它就会被清除,即使他们已经输入了数据
只有在有人点击现场时,它才会起作用
这将使用鼠标单击或键盘清除焦点上的文本区域。这将清除默认值onclick并恢复onblur
$('textarea').click(function () {
if (this.value == this.defaultValue) {
this.value = '';
}
});
$('textarea').blur(function () {
if (this.value === '') {
this.value = this.defaultValue;
}
});
或者,$this.val.$this.attr{value:};也可以表示为$this.val。
$('textarea').click(function () {
if (this.value == this.defaultValue) {
this.value = '';
}
});
$('textarea').blur(function () {
if (this.value === '') {
this.value = this.defaultValue;
}
});