0

我有一个文本区域,在页面加载时有一些文本。当有人点击它时,我希望该文本消失。当他们点击退出时,如果他们没有输入任何内容,我希望文本返回,但如果他们没有任何事情发生。文本是“在此处键入您的答案”。这就是我所拥有的,可用于在单击时删除文本,但如果他们没有键入任何内容,则不能将其重新添加。

$(".area-3").focusin(function() {
     $(".area-3").text(" ");
 }).focusout(function() {
    if ($(".area-3").val().length == 0) {
     $(".area-3").text("Type your answer here.");
    } 
 });

非常感谢您对此的任何帮助。

4

1 回答 1

3

像这样的东西:

$(".area-3").on({
    focus: function() {
       if (this.value == 'Type your answer here.') this.value = '';
    },
    blur: function() {
       if ( $.trim(this.value) == '') this.value = 'Type your answer here.';
    }
});

小提琴

于 2013-08-28T13:44:06.643 回答