我有一个文本区域,它在页面加载中包含一些文本。当有人点击它的时候,我想让它离开。当他们点击退出,如果他们没有输入任何东西,我希望文本回来,但如果他们没有什么事情发生。文本是‘在这里键入你的答案’。这是我的工作,以删除文本点击,但不是添加它回来,如果他们没有输入任何东西。
$(".area-3").focusin(function() {
$(".area-3").text(" ");
}).focusout(function() {
if ($(".area-3").val().length == 0) {
$(".area-3").text("Type your answer here.");
}
});非常感谢你在这方面的帮助。
发布于 2013-08-28 13:44:06
就像这样:
$(".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.';
}
});FIDDLE
https://stackoverflow.com/questions/18489656
复制相似问题